cancel
Showing results for 
Search instead for 
Did you mean: 

Using Java to manage LIST constraints...

wagon13
Champ in-the-making
Champ in-the-making
How do i retrieve the values of the LIST in Java… I have the following:


<constraints>
        <constraint name="dwr:sectorList" type="LIST">
            <parameter name="allowedValues">
                <list>
                    <value>Consumer Discretionary</value>
                    <value>Consumer Staples</value>
                    <value>Energy</value>
                    <value>Financials</value>
                    <value>Industrials</value>
                    <value>Materials</value>
                    <value>Technology</value>
                    <value>Telecommunications</value>
                    <value>Utilities</value>
                </list>
            </parameter>
            <parameter name="caseSensitive">
                <value>true</value>
            </parameter>
        </constraint>
    </constraints>

    <aspects>
        <aspect name="dwr:reportsMetaData">
            <title>Position Report</title>
            <properties>
                <property name="dwr:date">
                    <title>Date</title>
                    <type>d:datetime</type>
                </property>
                <property name="dwr:sector">
                    <title>Sector</title>
                    <type>d:text</type>
                    <constraints>
                        <constraint ref="dwr:sectorList" />
                    </constraints>
                </property>
        </aspect>
    </aspects>

This is mapped in the web-client-config-custom


<config>
         <dialogs>
         <!– Definition of the create space dialog –>
         <dialog name="createPositionReportSpace"
               page="/jsp/extension/create-position-reports-space/create-position-reports.jsp"
               managed-bean="CreatePositionReportSpaceDialog"
               icon="/images/icons/create_space_large.gif"
               title-id="create_space"
               description-id="create_space_description"
               error-message-id="error_create_space_dialog" />

         <!– Definition of the edit space dialog –>
         <dialog name="editPositionReportsSpace"
               page="/jsp/spaces/edit-space-dialog.jsp"
               managed-bean="EditPositionReportSpaceDialog"
               icon="/images/icons/details_large.gif"
               title-id="modify_space_properties"
               description-id="editspace_description" />
      </dialogs>
   </config>

   <config evaluator="aspect-name" condition="dwr:reportsMetaData">
      <property-sheet>
         <show-property name="dwr:date"/>
         <show-property name="dwr:sector" component-generator="TextFieldGenerator"/>
      </property-sheet>
   </config>

So, I have this working using the "base" metadata. I want to do 1 of 2 things… either use a propertySheetGrid when creating the space to display all the metadata to be populated by the user - OR - write a custom JSP.

If I do the proprtySheetGrid, how do I give it the correct node reference to use the metadata.

If I do the custom JSP I am writing the code to create the lists to be used in the <h:selectOneMenu>. I am able to access the aspect and get the PropertyDefinitions but unable to get the constraints…

I do something like this…

    AspectDefinition aspectDef = this.dictionaryService.getAspect(idQName);
    Iterator<PropertyDefinition> iterPropDefCol = aspectDef.getProperties().values().iterator();

     while (iterPropDefCol.hasNext()) {
          PropertyDefinition propDef = iterPropDefCol.next();
          if (propDef.getName().getLocalName().equals("sector")) {
              List<ConstraintDefinition> propConstraints = propDef.getConstraints();
             

I am trying to use ListOfValuesConstraint for displaying the list.

Am I completely confused here or doing something right?

Thanks!
1 REPLY 1

wagon13
Champ in-the-making
Champ in-the-making
Figured it out…

For those who struggle.. this is how I did it…



// idQName is the aspect you are looking up
AspectDefinition aspectDef = this.dictionaryService.getAspect(idQName);
Iterator<PropertyDefinition> iterPropDefCol = aspectDef.getProperties().values().iterator();

while (iterPropDefCol.hasNext()) {
   PropertyDefinition propDef = iterPropDefCol.next();
   if (propDef.getName().getLocalName().equals(property)) {

      // Go through the constaints and see if it has the list of values constraint.
      ListIterator<ConstraintDefinition> constraintsIter = propDef.getConstraints().listIterator();
      
      while (constraintsIter.hasNext()) {
         Constraint constraint = ((ConstraintDefinition) constraintsIter.next()).getConstraint();

         if (constraint instanceof ListOfValuesConstraint) {
            ListIterator<String> valuesIter = ((ListOfValuesConstraint) constraint).getAllowedValues().listIterator();
            while (valuesIter.hasNext()) {
               constraintsList.add(new SelectItem(valuesIter.next()));
            }

            return constraintsList;
         }
      }
   }
}