AnsweredAssumed Answered

Showing labels for a property with a list constraint

Question asked by glaenen on Jun 6, 2012
Latest reply on Jun 7, 2012 by glaenen
Hello,

I have implemented a ListOfValuesQueryConstraint to get the values and labels from a mysql database, this works without a problem.
But now I need to get Alfresco Share to show the labels when viewing document properties and show the label and store the values when editing properties.

My guess is that I should create a new from control for this property and use this instead of selectmany.ftl to get this done.
But I'm no expert on freemaker so I found an other solution.

In my ListOfValuesQueryContraint I also replaced the method getDisplayLabel for ListOfValuesConstraint

original:

public String getDisplayLabel(String constraintAllowableValue)
    {
        if (!this.allowedValues.contains(constraintAllowableValue))
        {
            return null;
        }
       
        String key = LOV_CONSTRAINT_VALUE;
        key += "." + this.getShortName();
        key += "." + constraintAllowableValue;
        key = StringUtils.replace(key, ":", "_");
       
        String message = I18NUtil.getMessage(key, I18NUtil.getLocale());
        return message == null ? constraintAllowableValue : message;
    }

replaced with:

public String getDisplayLabel(String constraintAllowableValue)
        {
            if (!super.getAllowedValues().contains(constraintAllowableValue))
            {
                return null;
            }
           
            String message = null;
            List<SelectItem> result = this.getSelectItemList();
            for (int i = 0; i < result.size(); i++) {
               if ( result.get(i).getValue().equals(constraintAllowableValue) ){
                  message = result.get(i).getLabel();
               }
            }
                       
         return message == null ? constraintAllowableValue : message;
        }

This now makes Alfresco Share show the labels when viewing and editing properties and store the values on the node.
Also Alfresco Explorer shows the label in the dropdown when editing properties. Only thing left to do is add a custom componnent generator for viewing in Alfresco Explorer.

It looks to me like this is a pretty good and simple solution so I wanted to share this.
If anyone has any thoughts on why this isn't such a good idea, please let me know.

Kind Regards,

Glenn

Outcomes