cancel
Showing results for 
Search instead for 
Did you mean: 

ParameterDefinitionImpl - with constraint

mtw999
Champ in-the-making
Champ in-the-making
Hi,

I'm using ParameterDefinitionImpl ctor that has takes a constraint as a String value. How do I specify the constraint if the constraint is defined in my model:

paramList.add(new ParameterDefinitionImpl(PARAM_MY_PARAM, DataTypeDefinition.TEXT, false,
        getParamDisplayLabel(PARAM_MY_PARAM), false, "mydocument:my_constraint"));

does not work.


  <constraint name="mydocument:my_constraint" type="LIST">
   <parameter name="allowedValues">
      <list>
        <value>asdf</value>
        <value>qwerty</value>
        <value>zzaa1</value>
        <value>1234</value>
      </list>
     </parameter>
    </constraint>
3 REPLIES 3

kaynezhang
World-Class Innovator
World-Class Innovator
The constraint you defined in model is used to constraint property of a type,it is a property constraint ,it can't be used as a parameter constraint for action directly.
If you want to use property constraint to constraint the list of allowable values for a action parameter ,you can do it like this.
1.Customize a class that inherit from org.alfresco.repo.action.constraint.BaseParameterConstraint, inject DictionaryService into your class.
2.Override method of getAllowableValuesImpl().in your getAllowableValuesImpl() do following
   a.Get the definition of your property constraint by calling DictionaryService.getConstraint()  ;
   b.Iterate the list of constrained values and construt  allowable parameter constraint values map.
3.Configure you class in spring configuration file and put it in extension classpath.
4.Pass the bean name your configured in spring as parameterConstraintName to ParameterDefinitionImpl constructor

new ParameterDefinitionImpl(PARAM_MY_PARAM, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_MY_PARAM), false, "bean name you configured in spring")

mtw999
Champ in-the-making
Champ in-the-making
Thank you. I discovered how this works by looking at source code and the Test Cases for ParameterDefinitionImpl. I appreciate your response and hopefully it will save someone time in the future. Assuming ParameterDefinitionImpl is a public interface, it would be nice to see a little better documentation from Alfresco. 🙂

sayeed
Champ in-the-making
Champ in-the-making

Hi Kayne Zhang,

I implemented the same procedure which is suggested and Iam able to get the values.This is very useful article.

But I noticed that getAllowableValuesImpl() method is called when I click on MangeRules,New Rule tab in alfresco share UI.

And I want that getAllowableValuesImpl() should be called only when I click on New Rule Tab ,as I have the requirement to display a dialog box when I click on New Rule and that logic I had configured in getAllowableValuesImpl() method.

Can you please suggest how to make getAllowableValuesImpl() to call on New Rule tab