List Constraint for a Repeating Metadata Field and Commas
In general it is possible to use Content Model Constraints to handle lists of acceptable values for a metadata field. However, the issue we had to address was how to use constraints when commas were present in the value, (eg 2,4-d) and the metadata field is repeating. Alfresco uses commas to signify a new value when a user enters fields using Share. Therefore if you provide a dropdown which contains, for example, a value of 2,4-D, when you save the value, alfresco assumes that you are setting two values, 2 and 4-D into the multivalued metadata field. Unfortunately, the values are not valid from a constraint perspective so you cannot save them to the content item.
We tried many different options to get around this, such as escaping the comma or using share forms config “options” parameter but none of them worked, alfresco always treated 2,4-D as two values and set the metadata field accordingly. Eventually we settled on the solution to use a constraint value without a comma and use Resource bundles to present a value including a comma to the user. Therefore, the user picks a value from the list as 2,4-D but the real value saved is 2-4-D. The solution is shown below.
1) List Constraint: Create a list constraint in your custom content model. Note that comma in 2,4-D has been replaced with – (2-4-D). 2-4-D IBE Imazapic 2-4-D …
<constraint name=”seed:activeList” type=”LIST”>
2) Configure Metadata field to use List constraint values
<!– Muti-value Metadata field that uses the constraint –>
<atomic>true</atomic> <!– index in the foreground –>
<stored>false</stored> <!– store the property value in the index –>
3) Configure a Model Resource Bundle. This maps the values stored in the constraint to the Display values seen in Share for the dropdown. The space in 2-4-D IBE is escaped with value \u0020IBE as you cannot have spaces in a property name.
4) Configure share form to allow for selectmany control to pick up constraint values.
<field id=”seed:active” read-only=”false” mandatory=”true” label-id=”label.nuf_active” set=”study-technical-properties” >
<control template=”/org/alfresco/components/form/controls/selectmany.ftl”> </control>