Thanks Li Ying, I got some information from http://today.java.net/pub/a/today/2006/01/19/webwork-validation.html?page=3#custom-validators but I do not want to reinvent the wheel (basically avoid coding my validation logic in java code). If I could have my <actionClass>-validation.xml structured as
<validators> *<country name="USA"> * <!-- Field Validators for email field --> <field name="email"> <field-validator type="required" short-circuit="true"> <message>You must enter a value for email.</message> </field-validator> <field-validator type="email" short-circuit="true"> <message>Not a valid e-mail.</message> </field-validator> </field> <!-- Plain Validator 1 --> <validator type="expression"> <param name="expression">email.equals(email2)</param> <message>Email not the same as email2</message> </validator> *</country>* *<country name="AUSTRIA"> * <!-- Field Validators for email2 field --> <field name="email2"> <field-validator type="email"> <message>Not a valid e-mail2.</message> </field-validator> </field> <!-- Plain Validator 2 --> <validator type="expression" short-circuit="true"> <param name="expression">email.startsWith('mark')</param> <message>Email does not start with mark</message> </validator> *</country>* </validators> I am looking for something like a wrapper on existing bundled validators. Is it possible. Regards, JK. On Sun, Nov 27, 2011 at 10:06 PM, Li Ying <liying.cn.2...@gmail.com> wrote: > If your validate rules are fixed, only some parameters (integer/date > format or something else) relies on the country setting, I suggest you > implement it by retrieve the params via OGNL expression. > > The parameter for the Validators can be OGNL expression. > These docs may help: > http://struts.apache.org/2.x/docs/ognl.html > http://commons.apache.org/ognl/language-guide.html > > > If your validate rules are variable, you can implement your own > Validator, and register it into struts2. > Then, you can use it in the same way as you use the "Bundled Validators". > > This documents may help: > > http://struts.apache.org/2.x/docs/validation.html#Validation-RegisteringValidators > > To learn how to write a validator, you can read the source code of > Struts2/xWork, in package > [com.opensymphony.xwork2.validator.validators] > > And you can find some samples via google. > > > 2011/11/28 Jyothrilinga Rao <jyoth...@gmail.com>: > > Hi all, > > > > I am currently making use of the validator and able to work-out a example > > as discussed at http://struts.apache.org/2.x/docs/validation.html. > > > > My application has a concept of user's country which is stored in > session. > > Now depending on the value of this attribute stored in session, I need to > > have different validation rules for the same form and action. I would > still > > like to define validations outside of my action and JSP in a XML file. > > Is there something out of box provided which can fulfill my requirement ? > > or is there something I can extend on to fulfill this ? > > > > Thanks, > > JK. > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > >