Struts2 validator

i m facing to a struts validator problem.

I has an object like this:

public class Reconstitution {
       private List<FormuleReconstitution> formuleList;
      ...
      ...some other attributes and methods...
}

and :

public class FormuleReconstitution{
    private Map<Long, ElementFormuleReconstitution> serieMap;
    ...
    ...some other attributes and methods...
}

and

public class ElementFormuleReconstitution {
    private Double coefficient;
}

i would like to add a validator on coefficient in MyAction-validation.xml but i don't know how to do this. I know how to add a simple validator but not when i have sublist with submap :(

my generated html code look like this :

<input type="text" class="texte" id="reconstitutionformuleList0listeElementFormuleReconstitution0coefficient" tabindex="0" value="" name="reconstitution.formuleList[0].listeElementFormuleReconstitution[0].coefficient"/>

how can i add a validator on the field Coefficient ?

Upvotes: 1

Views: 263

Answers (1)

Andrea Ligios
Andrea Ligios

Reputation: 50281

To validate an object inside a List, you need to use the Visitor Validator.

Then, to validate a double with min/max range, you need:

<field name="coefficient">
    <field-validator type="double">
        <param name="minInclusive">0.0</param>
        <param name="maxInclusive">1000.0</param>
        <message>
            The coefficient must be between ${minInclusive} and ${maxInclusive}
        </message>
    </field-validator>
</field>

Finally, I suggest you to read how the INPUT result works (for both Validation and Conversion errors)

Upvotes: 1

Related Questions