You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Muralidhar Yaragalla <ja...@gmail.com> on 2013/03/24 16:39:50 UTC
How to validate multiple fields with the same name
Hi In my form i have 4 textfields with the same name so how do i validate
this using validation frame work. The validation for this 4 fields is, out
of 4 fields 2 fields are mandatory and no field should contain special
characters. So can this be done using validation frame work or do i have to
do custom valiation in my validate() method inside action class.
--
Thanks And Regards,
*Muralidhar Yaragalla.
*
Re: How to validate multiple fields with the same name
Posted by Muralidhar Yaragalla <ja...@gmail.com>.
Hi thanks for this. It is really helpful.
On Tue, Mar 26, 2013 at 12:13 AM, Lukasz Lenart <lu...@apache.org>wrote:
> 2013/3/25 Muralidhar Yaragalla <ja...@gmail.com>:
> > Hi Thanks for this.But i am aware of this info I mean the normal
> validation
> > methods. I repeat and the important point is that all the 4 fields i have
> > contains the same name so how do i do that in an xml. I know that it can
> be
> > done inside valiadtion() method. I thought so much but it looks
> impossible
> > for me to do in validation.xml file using validators.
>
> But in action is just one field? eg. private List<String> values? So
> the field name is values and you can use expression validator to have
> at least to fields filled:
>
> <field name="values">
> <field-validator type="fieldexpression">
> <param name="expression">(values.size > 1)</param>
> <message><![CDATA[ at least two values are
> required ]]></message>
> </field-validator>
> </field>
>
>
> Regards
> --
> Łukasz
> + 48 606 323 122 http://www.lenart.org.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
--
Thanks And Regards,
*Muralidhar Yaragalla.
*
Re: How to validate multiple fields with the same name
Posted by Lukasz Lenart <lu...@apache.org>.
2013/3/25 Muralidhar Yaragalla <ja...@gmail.com>:
> Hi Thanks for this.But i am aware of this info I mean the normal validation
> methods. I repeat and the important point is that all the 4 fields i have
> contains the same name so how do i do that in an xml. I know that it can be
> done inside valiadtion() method. I thought so much but it looks impossible
> for me to do in validation.xml file using validators.
But in action is just one field? eg. private List<String> values? So
the field name is values and you can use expression validator to have
at least to fields filled:
<field name="values">
<field-validator type="fieldexpression">
<param name="expression">(values.size > 1)</param>
<message><![CDATA[ at least two values are required ]]></message>
</field-validator>
</field>
Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: How to validate multiple fields with the same name
Posted by Muralidhar Yaragalla <ja...@gmail.com>.
Hi Thanks for this.But i am aware of this info I mean the normal validation
methods. I repeat and the important point is that all the 4 fields i have
contains the same name so how do i do that in an xml. I know that it can be
done inside valiadtion() method. I thought so much but it looks impossible
for me to do in validation.xml file using validators.
On Mon, Mar 25, 2013 at 1:44 PM, Pranava Swaroop
<st...@gmail.com>wrote:
> Murali , Apologies its not exactly interceptors, Two ways we can validate
> the input fields , one is using the configuration set for each of the
> fields and the other is programatic way.
>
> For example say we need to create a validation xml for user login, we
> create User-validation.xml (Format is Action-validation.xml for different
> classes). I just referred few inbuilt validators in the struts 2 site and
> below are the ones
>
>
> -
>
> required validator.
> -
>
> requiredstring validator
> -
>
> int validator
> -
>
> date validator
> -
>
> expression validator
> -
>
> fieldexpression validator
> -
>
> email validator
> -
>
> url validator
> -
>
> visitor validator
> -
>
> conversion validator
> -
>
> stringlength validator
> -
>
> regex validator
>
> And these dont require registration when you are using them in your
> application. Just add the action validation xml to the classes
> directory.
> It works
>
>
> <!DOCTYPE validators PUBLIC
> "-//OpenSymphony Group//XWork Validator 1.0.2//EN" "
> http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
> <validators>
> <field name="userName">
> <field-validator type="requiredstring">
> <message>Username is required</message>
> </field-validator>
> </field>
> <field name="password">
> <field-validator type="requiredstring">
> <message>Password is required</message>
> </field-validator>
> </field>
> </validators>
>
> This is one of the easiest solutions to isolate the most commonly used
> validations for the fields using configuration in struts2.
>
> Hope this helps. Thanks
>
> On 25 March 2013 16:25, Muralidhar Yaragalla <java.yaragalla@gmail.com
> >wrote:
>
> > Hi can you explain in brief how to do with interceptor(built in)?
> >
> >
> > On Mon, Mar 25, 2013 at 2:13 AM, Pranava Swaroop
> > <st...@gmail.com>wrote:
> >
> > > It could be done with buit in interceptors using configuration files or
> > > using the programming
> > >
> > > On Monday, 25 March 2013, Muralidhar Yaragalla wrote:
> > >
> > > > Hi In my form i have 4 textfields with the same name so how do i
> > validate
> > > > this using validation frame work. The validation for this 4 fields
> is,
> > > out
> > > > of 4 fields 2 fields are mandatory and no field should contain
> special
> > > > characters. So can this be done using validation frame work or do i
> > have
> > > to
> > > > do custom valiation in my validate() method inside action class.
> > > >
> > > > --
> > > > Thanks And Regards,
> > > > *Muralidhar Yaragalla.
> > > > *
> > > >
> > >
> > >
> > > --
> > > Keep looking Don't Settle
> > >
> >
> >
> >
> > --
> > Thanks And Regards,
> > *Muralidhar Yaragalla.
> > *
> >
>
>
>
> --
> Warm Regards
> Pranava S Balugari
>
> "Keep Looking Don't Settle"
>
--
Thanks And Regards,
*Muralidhar Yaragalla.
*
Re: How to validate multiple fields with the same name
Posted by Pranava Swaroop <st...@gmail.com>.
Murali , Apologies its not exactly interceptors, Two ways we can validate
the input fields , one is using the configuration set for each of the
fields and the other is programatic way.
For example say we need to create a validation xml for user login, we
create User-validation.xml (Format is Action-validation.xml for different
classes). I just referred few inbuilt validators in the struts 2 site and
below are the ones
-
required validator.
-
requiredstring validator
-
int validator
-
date validator
-
expression validator
-
fieldexpression validator
-
email validator
-
url validator
-
visitor validator
-
conversion validator
-
stringlength validator
-
regex validator
And these dont require registration when you are using them in your
application. Just add the action validation xml to the classes directory.
It works
<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN" "
http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
<field name="userName">
<field-validator type="requiredstring">
<message>Username is required</message>
</field-validator>
</field>
<field name="password">
<field-validator type="requiredstring">
<message>Password is required</message>
</field-validator>
</field>
</validators>
This is one of the easiest solutions to isolate the most commonly used
validations for the fields using configuration in struts2.
Hope this helps. Thanks
On 25 March 2013 16:25, Muralidhar Yaragalla <ja...@gmail.com>wrote:
> Hi can you explain in brief how to do with interceptor(built in)?
>
>
> On Mon, Mar 25, 2013 at 2:13 AM, Pranava Swaroop
> <st...@gmail.com>wrote:
>
> > It could be done with buit in interceptors using configuration files or
> > using the programming
> >
> > On Monday, 25 March 2013, Muralidhar Yaragalla wrote:
> >
> > > Hi In my form i have 4 textfields with the same name so how do i
> validate
> > > this using validation frame work. The validation for this 4 fields is,
> > out
> > > of 4 fields 2 fields are mandatory and no field should contain special
> > > characters. So can this be done using validation frame work or do i
> have
> > to
> > > do custom valiation in my validate() method inside action class.
> > >
> > > --
> > > Thanks And Regards,
> > > *Muralidhar Yaragalla.
> > > *
> > >
> >
> >
> > --
> > Keep looking Don't Settle
> >
>
>
>
> --
> Thanks And Regards,
> *Muralidhar Yaragalla.
> *
>
--
Warm Regards
Pranava S Balugari
"Keep Looking Don't Settle"
Re: How to validate multiple fields with the same name
Posted by Muralidhar Yaragalla <ja...@gmail.com>.
Hi can you explain in brief how to do with interceptor(built in)?
On Mon, Mar 25, 2013 at 2:13 AM, Pranava Swaroop
<st...@gmail.com>wrote:
> It could be done with buit in interceptors using configuration files or
> using the programming
>
> On Monday, 25 March 2013, Muralidhar Yaragalla wrote:
>
> > Hi In my form i have 4 textfields with the same name so how do i validate
> > this using validation frame work. The validation for this 4 fields is,
> out
> > of 4 fields 2 fields are mandatory and no field should contain special
> > characters. So can this be done using validation frame work or do i have
> to
> > do custom valiation in my validate() method inside action class.
> >
> > --
> > Thanks And Regards,
> > *Muralidhar Yaragalla.
> > *
> >
>
>
> --
> Keep looking Don't Settle
>
--
Thanks And Regards,
*Muralidhar Yaragalla.
*
Re: How to validate multiple fields with the same name
Posted by Pranava Swaroop <st...@gmail.com>.
It could be done with buit in interceptors using configuration files or
using the programming
On Monday, 25 March 2013, Muralidhar Yaragalla wrote:
> Hi In my form i have 4 textfields with the same name so how do i validate
> this using validation frame work. The validation for this 4 fields is, out
> of 4 fields 2 fields are mandatory and no field should contain special
> characters. So can this be done using validation frame work or do i have to
> do custom valiation in my validate() method inside action class.
>
> --
> Thanks And Regards,
> *Muralidhar Yaragalla.
> *
>
--
Keep looking Don't Settle