You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Zhang, Larry (L.)" <lz...@ford.com> on 2008/02/01 15:45:28 UTC

RE: Struts validator

 
Can some Struts guru answer the following questions?
-----Original Message-----
From: Zhang, Larry (L.) 
Sent: Thursday, January 31, 2008 3:27 PM
To: 'Struts Users Mailing List'
Subject: Struts validator

Hello coworkers,

I have a questions regarding the struts validation..., say I have three
text fields to be validated in struts validation, and three submit
buttons as well. When I submit one buttion, I only need to validate one
field, and when I click on the other submit button, I need to validate
the other field. Currently, all three fields are validated even though I
don't need to. Is there any way to overcome this issue?

Thanks. 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Struts validator

Posted by "Zhang, Larry (L.)" <lz...@ford.com>.
Struts valdiator developers, Doesn't struts support this requirment?

-----Original Message-----
From: Zhang, Larry (L.) 
Sent: Friday, February 01, 2008 10:55 AM
To: 'Struts Users Mailing List'
Subject: RE: Struts validator


No, I am using struts 1.1, I would like to implement the following case:
In valiation.xml:

 <form name="/myAction">
		 <!--if submit button 1 clicked, I validate the
following field>-->
		<field property="myProperty" depends="required">
			<msg name="required" key="error.key1" />
		</field>   

		<!--if submit button 2 clicked, I validate the following
field>-->
		<field property="name" depends="myValidator">
			<msg name="myValidator"	key="error.key2" /> 
		</field>
</form>  


I don't want to validate both fields at the same time when just one
submit button is clicked. Your helps are appreciated!

-----Original Message-----
From: Dave Newton [mailto:newton.dave@yahoo.com] 
Sent: Friday, February 01, 2008 10:45 AM
To: Struts Users Mailing List
Subject: RE: Struts validator

--- "Zhang, Larry (L.)" <lz...@ford.com> wrote:
> We are not using Struts 2 tag and thus I can't use s:submit tag. 

Are you using Struts 2 at all?

You can still use the generated HTML as a template to create your own
HTML,
although... not sure why you wouldn't just use the tag in this case.

Dave


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Struts validator

Posted by Alexandru BARBAT <al...@ucs.ro>.
Hi,

You can override method 
 public String getValidationKey(ActionMapping mapping,
                                   HttpServletRequest request) {..}

>From your ValidatorForm (it doesn't matter if it is dyna or not)

And return different validation keys for each button pressed.

Validation key identify the rules of validation.

The validation file will look then something like:

<form name="myAction_button1">
		 <!--if submit button 1 clicked, I validate the
following field>-->
		<field property="myProperty" depends="required">
			<msg name="required" key="error.key1" />
		</field>   
</form>

<form name="myAction_button2">
		<!--if submit button 2 clicked, I validate the following
field>-->
		<field property="name" depends="myValidator">
			<msg name="myValidator"	key="error.key2" /> 
		</field>
</form>


alex

-----Original Message-----
From: Dave Newton [mailto:newton.dave@yahoo.com] 
Sent: Friday, February 01, 2008 6:29 PM
To: Struts Users Mailing List
Subject: RE: Struts validator

--- "Zhang, Larry (L.)" <lz...@ford.com> wrote:
> No, I am using struts 1.1,

Oh, wow.

Does validwhen[1] not exist in S1.1? You can always create a custom
validator
as well if you find your validation stretches what's easy to do with the
existing validation configuration possibilities. You may also be able to
combine declarative validation (via XML) and Java-based validation, although
it's been a pretty long time since I've thought about that :)

Dave

[1] http://struts.apache.org/1.1/userGuide/dev_validator.html (about 1/3 of
the way down)


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Struts validator

Posted by Dave Newton <ne...@yahoo.com>.
--- "Zhang, Larry (L.)" <lz...@ford.com> wrote:
> No, I am using struts 1.1,

Oh, wow.

Does validwhen[1] not exist in S1.1? You can always create a custom validator
as well if you find your validation stretches what's easy to do with the
existing validation configuration possibilities. You may also be able to
combine declarative validation (via XML) and Java-based validation, although
it's been a pretty long time since I've thought about that :)

Dave

[1] http://struts.apache.org/1.1/userGuide/dev_validator.html (about 1/3 of
the way down)


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Struts validator

Posted by "Zhang, Larry (L.)" <lz...@ford.com>.
No, I am using struts 1.1, I would like to implement the following case:
In valiation.xml:

 <form name="/myAction">
		 <!--if submit button 1 clicked, I validate the
following field>
		<field property="myProperty" depends="required">
			<msg name="required" key="error.key1" />
		</field>   

		<!--if submit button 2 clicked, I validate the following
field>
		<field property="name" depends="myValidator">
			<msg name="myValidator"	key="error.key2" /> 
		</field>
</form>  


I don't want to validate both fields at the same time when just one
submit button is clicked. Your helps are appreciated!

-----Original Message-----
From: Dave Newton [mailto:newton.dave@yahoo.com] 
Sent: Friday, February 01, 2008 10:45 AM
To: Struts Users Mailing List
Subject: RE: Struts validator

--- "Zhang, Larry (L.)" <lz...@ford.com> wrote:
> We are not using Struts 2 tag and thus I can't use s:submit tag. 

Are you using Struts 2 at all?

You can still use the generated HTML as a template to create your own
HTML,
although... not sure why you wouldn't just use the tag in this case.

Dave


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Struts validator

Posted by Dave Newton <ne...@yahoo.com>.
--- "Zhang, Larry (L.)" <lz...@ford.com> wrote:
> We are not using Struts 2 tag and thus I can't use s:submit tag. 

Are you using Struts 2 at all?

You can still use the generated HTML as a template to create your own HTML,
although... not sure why you wouldn't just use the tag in this case.

Dave


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Struts validator

Posted by "Zhang, Larry (L.)" <lz...@ford.com>.
We are not using Struts 2 tag and thus I can't use s:submit tag. 

-----Original Message-----
From: David Harland [mailto:dharland@ufi.com] 
Sent: Friday, February 01, 2008 10:01 AM
To: Struts Users Mailing List
Subject: RE: Struts validator

You can do it by having 3 different methods such as

method1() method2() method3() and then have 

validateMethod1() validateMethod2() validateMethod3() 

then in your form 

<s:submit key="button.method1" method="method1"/> 
<s:submit key="button.method2" method="method2"/> 
<s:submit key="button.method3" method="method3"/> 

or you can do by using action aliases and have three validation xml
files.

http://struts.apache.org/2.0.11/docs/validation.html

-----Original Message-----
From: Zhang, Larry (L.) [mailto:lzhang20@ford.com] 
Sent: 01 February 2008 14:45
To: Struts Users Mailing List
Subject: RE: Struts validator

 
Can some Struts guru answer the following questions?
-----Original Message-----
From: Zhang, Larry (L.)
Sent: Thursday, January 31, 2008 3:27 PM
To: 'Struts Users Mailing List'
Subject: Struts validator

Hello coworkers,

I have a questions regarding the struts validation..., say I have three
text fields to be validated in struts validation, and three submit
buttons as well. When I submit one buttion, I only need to validate one
field, and when I click on the other submit button, I need to validate
the other field. Currently, all three fields are validated even though I
don't need to. Is there any way to overcome this issue?

Thanks. 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


- ------
ML {UFI}

______________________________________________________________________
Ufi Limited 
Registered in England No.  3980770 
Registered Office:  Dearing House, 1 Young Street, Sheffield, S1 4UP 

learndirect Solutions Ltd 
Registered in England No. 5081669 
Registered Office:  Dearing House, 1 Young Street, Sheffield, S1 4UP 

UFI Charitable Trust 
Registered in England No.  3658378 
Registered Charity No.  1081028 
Registered Office:  Dearing House, 1 Young Street, Sheffield, S1 4UP 

This email has been scanned by the MessageLabs Email Security System.

______________________________________________________________________

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Struts validator

Posted by David Harland <dh...@ufi.com>.
You can do it by having 3 different methods such as

method1() method2() method3() and then have 

validateMethod1() validateMethod2() validateMethod3() 

then in your form 

<s:submit key="button.method1" method="method1"/> 
<s:submit key="button.method2" method="method2"/> 
<s:submit key="button.method3" method="method3"/> 

or you can do by using action aliases and have three validation xml
files.

http://struts.apache.org/2.0.11/docs/validation.html

-----Original Message-----
From: Zhang, Larry (L.) [mailto:lzhang20@ford.com] 
Sent: 01 February 2008 14:45
To: Struts Users Mailing List
Subject: RE: Struts validator

 
Can some Struts guru answer the following questions?
-----Original Message-----
From: Zhang, Larry (L.)
Sent: Thursday, January 31, 2008 3:27 PM
To: 'Struts Users Mailing List'
Subject: Struts validator

Hello coworkers,

I have a questions regarding the struts validation..., say I have three
text fields to be validated in struts validation, and three submit
buttons as well. When I submit one buttion, I only need to validate one
field, and when I click on the other submit button, I need to validate
the other field. Currently, all three fields are validated even though I
don't need to. Is there any way to overcome this issue?

Thanks. 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


- ------
ML {UFI}

______________________________________________________________________
Ufi Limited 
Registered in England No.  3980770 
Registered Office:  Dearing House, 1 Young Street, Sheffield, S1 4UP 

learndirect Solutions Ltd 
Registered in England No. 5081669 
Registered Office:  Dearing House, 1 Young Street, Sheffield, S1 4UP 

UFI Charitable Trust 
Registered in England No.  3658378 
Registered Charity No.  1081028 
Registered Office:  Dearing House, 1 Young Street, Sheffield, S1 4UP 

This email has been scanned by the MessageLabs Email Security System.

______________________________________________________________________

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org