Programmatic output of a property's constraints

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2009 07:38 AM
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.
Unfortunately, all I get is a single entry "status_anon_13". What would be the correct code to produce the desired listbox entries?
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?
Labels:
- Labels:
-
Archive
1 REPLY 1

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2009 09:02 AM
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;}
