Wednesday, October 22, 2014

Faceted forms - form based on node state (metadata)

A nice thing about Alfresco Share is that, you get a lot of functionality for free and it is very adaptable. But often you want more client-side adaptability and the first think that comes into mind is client-side Javascript. To avoid client-side javascript customization on Share I made a special form evaluator, which gives you the power to have different forms for the same node type, depending on the state/metadata values.

Normally you define a node type form for view and edit of existing nodes:

 <config evaluator="node-type" condition="my:nodeType"> ...

This is one time solution for alle nodes of this type and lifecycle. To use a facetted approach, you could now add form configuration depending on a metadata property, like:

  <config evaluator="facet-node-type" condition="my:nodeType,my:state=open">

and another

  <config evaluator="facet-node-type" condition="my:nodeType,my:state=closed">

This means (given this facet-node-type exists and works :) you should have a resulting form configuration of the 'node-type' and one 'facet-node-type' given your node either have state 'open' or 'closed'

This evaluation is done Share-server-side, so the state (my:state) should preferable be read-only in the resulting forms.

In my example we could have a text field for an 'open' node and none for a 'closed' on.

To make this work we need to define the 'facet-node-type' in the form-config xml

      <evaluator id="facet-node-type" class="com.redpill-linpro.alfresco.web.config.forms.FacetNodeTypeEvaluator" />


and mainly the java code Source

Finally lets show the full 'condition' definition available:

General format


Where <node-type> is the prefix-nodetype  like in the standard node-type evaluator ...

Where <property-evals> is of the format:


And <property-eval> is of the format


So I could write the following to select only 'my:node-type' nodes with 'my:state' 'open' or 'closed' and 'my:color' set to 'blue'


This can be used to have a form definition where one-large common form (section) is defined and various small modifications of this is in facet-node-type sections depending on the metadata of the node.