cancel
Showing results for 
Search instead for 
Did you mean: 

Programmatic output of a property's constraints

burriad
Champ in-the-making
Champ in-the-making
Hi,

I am looking for a way to programmatically retrieve the values of a list constraint. The example below tries to do exactly this, but does not work as expected.

public List<SelectItem> getStatusValues() {
   PropertyDefinition pd = getDictionaryService().getProperty(MyModel.STATUS_PROP);
   List<SelectItem> result = new ArrayList<SelectItem>();
      
   for (ConstraintDefinition cd : pd.getConstraints()) {
      cd.getConstraint().
      result.add(new SelectItem(cd.getName().getLocalName()));
   }

   return result;
}
So the expected output in a listbox would be two entries with values "open" and "closed", given the constraint definition below.

<constraint name="enum-status" type="LIST">
  <parameter name="allowedValues">
     <list>
   <value>open</value>
   <value>closed</value>
    </list>
  </parameter>
</constraint>

<property name="status">
  …
  <constraints>
    <constraint ref="enum-status"/>
  </constraints>
</property>

Unfortunately, all I get is a single entry "status_anon_13". What would be the correct code to produce the desired listbox entries?
1 REPLY 1

burriad
Champ in-the-making
Champ in-the-making
Life's not that hard sometimes. A little cast saves the day:

public List<SelectItem> getStatusValues() {
   PropertyDefinition pd = getDictionaryService().getProperty(MyModel.STATUS_PROP);
   List<SelectItem> result = new ArrayList<SelectItem>();
     
   for (ConstraintDefinition cd : pd.getConstraints()) {
      if (cd.getConstraint() instanceof ListOfValuesConstraint) {
            ListOfValuesConstraint lc = (ListOfValuesConstraint) cd.getConstraint()
            for (String val : lc.getAllowedValues()) {
                result.add(new SelectItem(val));
            }
       }
   }

   return result;
}
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.