I am creating a sample application with two methods(execute,addEmployee) in a same action class(Employee.java). I need to validate some common fields in both the methods and I have some method specific validations. My Employee.java code is:
public class Employee extends ActionSupport{
public String execute()
{
return SUCCESS;
}
public String addEmployee()
{
return SUCCESS;
}
}
And validation files:
Employee-validation.xml code to validate required field validations for name and age fields.
Employee-execute-validation.xml
<field name="age">
<field-validator type="int">
<param name="min">10</param>
<param name="max">40</param>
<message>Age must be in between 10 and 40</message>
</field-validator>
</field>
Employee-addEmployee-validation.xml
<field name="gender">
<field-validator type="int">
<param name="min">1</param>
<message>Please select a value</message>
</field-validator>
</field>
But while running, only rules defined in Employee-validation.xml works.
Please help me with this.
Validation could be defined per action aliases not per methods.
<actionClass>-<actionAlias>-validation.xml
The actionAlias here refers to the action name in configuration not method in action class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With