You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by fea jabi <zy...@hotmail.com> on 2005/11/18 21:51:43 UTC

struts validator

Have a jsp with a checkbox.

If this is checked have to make sure 2 other textfields are not empty.

<validator name="confirm"
classname="org.apache.struts.validator.FieldChecks"
method="validateConfirm"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionMessages,
org.apache.commons.validator.Validator,
javax.servlet.http.HttpServletRequest"
depends=""
msg="errors.setup">
<javascript>
<![CDATA[
funtion validateConfirm(form){
alert("Inside validate function");
}
]]>
</javascript>
</validator>

I am not sure what to write in below. any help is appreciated.


<formset>
<form name="Form1">
<field property="confirm" depends="">
<arg key=""/>
</field>
</form>
</formset>

from jsp how to call this javascript function?

Thanks.

_________________________________________________________________
Don’t just search. Find. Check out the new MSN Search! 
http://search.msn.click-url.com/go/onm00200636ave/direct/01/


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


Re: struts validator

Posted by Laurie Harper <la...@holoweb.net>.
fea jabi wrote:
> Have a jsp with a checkbox.
> 
> If this is checked have to make sure 2 other textfields are not empty.
> 
> <validator name="confirm"
> classname="org.apache.struts.validator.FieldChecks"
> method="validateConfirm"
> methodParams="java.lang.Object,
> org.apache.commons.validator.ValidatorAction,
> org.apache.commons.validator.Field,
> org.apache.struts.action.ActionMessages,
> org.apache.commons.validator.Validator,
> javax.servlet.http.HttpServletRequest"
> depends=""
> msg="errors.setup">
> <javascript>
> <![CDATA[
> funtion validateConfirm(form){
> alert("Inside validate function");
> }
> ]]>
> </javascript>
> </validator>
> 
> I am not sure what to write in below. any help is appreciated.
> 
> 
> <formset>
> <form name="Form1">
> <field property="confirm" depends="">
> <arg key=""/>
> </field>
> </form>
> </formset>
> 
> from jsp how to call this javascript function?

Firstly, why are you trying to write your own validator rule rather than 
using the existing 'validwhen' rule? See the documentation on validwhen 
[1] for examples of how to do what you want with that.

If you really do want to set up your own validator rule for some reason, 
you would use it the same as the standard rules: in validation.xml you 
set depends to the name of the validation rule ('confirm' in this case; 
then you include the html:javascript [2] tag in your form and supply the 
appropriate onsubmit handler on the html:form tag. See the Resources 
section [3] of the validator guide for some links to tutorials and 
articles which should get you up and running.

L.

[1] 
http://struts.apache.org/struts-doc-1.2.7/userGuide/dev_validator.html#validwhen
[2] 
http://struts.apache.org/struts-doc-1.2.7/userGuide/struts-html.html#javascript
[3] 
http://struts.apache.org/struts-doc-1.2.7/userGuide/dev_validator.html#resources


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