cancel
Showing results for 
Search instead for 
Did you mean: 

How read aspect fields values in a custom constraint

nahanni
Champ in-the-making
Champ in-the-making
Hi,

I have developped a custom constraint. This constraint is linked to a field in an aspect.

In this constraint, I need to read values in other fields of the aspect.

I tried

String val = (String) context.getExternalContext().getRequestParameterMap().get("the_field"); 
but it doesn't work !


The following go show in the console that the fields of the aspect are not present in the map returned by getRequestParameterMap.

int i=0;
for (Iterator it=context.getExternalContext().getRequestParameterMap().keySet().iterator(); it.hasNext(); i++) {
      Object key = it.next();
      Object value = context.getExternalContext().getRequestParameterMap().get(key);
      System.out.println("\nkey["+i+"]: "+key+" = value["+i+"]: "+value);
}

Any idea on how acces to the other fields values ?

Thank you.

Dom
3 REPLIES 3

gavinc
Champ in-the-making
Champ in-the-making
If you're talking about fields that are present on the web page they should be bound to a backing bean, in which case the value of the field will end up in the appropriate member variable of your bean.

For example if you have:

<h:inputText value="#{MyBean.name}" />

then the class:

public class MyBean
{
    private String name;

    public void setName(String name)
    {
        this.name = name;
    }

    public String getName()
    {
        return this.name;
    }
}

Then the value of the name field in the UI will end up in the name variable and thus accessible via MyBean.getName().

Hope this helps.

nahanni
Champ in-the-making
Champ in-the-making
Thank you.

I don't have

<h:inputText value="#{MyBean.name}" />

I have a custom aspect with fields associeted with custom componet generator and linked to a custom constraint.

          
<constraint name="custom:Continent" type="org.alfresco.repo.dictionary.constraint.ListOfCategoriesConstraint">
    <parameter name="allowedValues">
        <list>
        </list>
    </parameter>
    <parameter name="caseSensitive"><value>true</value></parameter>
    <parameter name="rootCategory"><value>Regions</value></parameter>
    <parameter name="fatherFields"><value></value></parameter>
</constraint>


<property name="custom:Continent" component-generator="TextFieldCategoryGenerator">
    <title>Continent</title>
    <type>d:text</type>
    <constraints>
        <constraint ref="custom:Continent" />  
    </constraints>
</property>


As parameter "allowedValues" is present but "list" are empty, the component generator (derived from TextFieldCategoryGenerator) create a select one input with onchange="submit()" attribut and linked to a ="org.alfresco.repo.dictionary.constraint.ListOfCategoriesConstraint" constraint

The constraint read categories to populate the list (I have on list in the aspect for each level in the category)

If I select a category in the first list (continent), the edit-content-property form is refresh (due to the onchange="submit()")

In the constraint I need to read value father list in the constraint in order to populate the second level list (continent zone) with appropriate values

I have 2 problems :

1. how read the value in other fields at reload time

2. the constraints are not called at reload time but only at the first aspect display (when I start editing properties for a document)

If you have any suggestion, it would be great.

Thank you

Dom

gavinc
Champ in-the-making
Champ in-the-making
This is the wrong place for component-generator, this is the model configuration file, component-generator goes in the client side (web client) config files, see web-client-config-properties.xml.

You shouldn't need this anyway, as long as you add "custom:Continent" to a property sheet config the list of values should appear automatically. Your config should look something like:


<property-sheet>
   <show-property name="custom:Contient"/>
</property-sheet>

As for changing the values in one list dependent on another, this is something we don't support, see this forum post for details: http://forums.alfresco.com/viewtopic.php?p=21602#21602

Hope this helps.