cancel
Showing results for 
Search instead for 
Did you mean: 

Showing labels for a property with a list constraint

glaenen
Champ in-the-making
Champ in-the-making
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
1 REPLY 1

glaenen
Champ in-the-making
Champ in-the-making
To make the list dynamic (not having to restart Alfresco for each entry added in the database) I added

public List<String> getAllowedValues(){
           this.loadDB();
           return super.getAllowedValues();
        }

to my contraint.

This made the getDisplayLabel method from my first post to trigger a loadDB for each label.
So I had to change to way a value is translated into a label.

public String getDisplayLabel(String constraintAllowableValue)
        {
            if (!super.getAllowedValues().contains(constraintAllowableValue))
            {
                return null;
            }
            String message = this.getAllowedLabels().get(super.getAllowedValues().indexOf(constraintAllowableValue));
            return message == null ? constraintAllowableValue : message;
        }