Did anyone try to use requiredif or validwhen in a webapp successfully?
I try to use it, but it does not work.
I read the spec, it wrote the requiredif is default in validator lib.
Then I open the validation-rule.xml, I found that there is no javascript in requiredif tag, it is unlike required tag.
Please tell me the solution if you can use requiredif in your project!
Many Thanks.
-
Struts Validator requiredif (6 messages)
- Posted by: Frankie Wong
- Posted on: October 07 2004 04:23 EDT
Threaded Messages (6)
- Struts Validator requiredif by M. Ho on November 01 2004 20:06 EST
- Struts validation requiredif by Hideki Mae on January 04 2005 15:49 EST
-
Struts validation requiredif by Kishore Senji on January 14 2005 01:52 EST
-
Does validation generate a javascript alert? by fl z on March 22 2005 10:24 EST
- validwhen and requiredif do not work! by Meena Venkat on November 11 2009 09:12 EST
-
Does validation generate a javascript alert? by fl z on March 22 2005 10:24 EST
- Re: Struts validation requiredif by Meena Venkat on November 11 2009 09:14 EST
-
Struts validation requiredif by Kishore Senji on January 14 2005 01:52 EST
- Struts validation requiredif by Hideki Mae on January 04 2005 15:49 EST
-
Struts Validator requiredif[ Go to top ]
- Posted by: M. Ho
- Posted on: November 01 2004 20:06 EST
- in response to Frankie Wong
I have used it successfully. This is the validation.xml
<form name="registrationForm">
<field property="fromAddress"
depends="required,email">
<arg0 key="prompt.fromAddress"/>
</field>
<field property="fullName"
depends="required">
<arg0 key="prompt.fullName"/>
</field>
<field property="replyToAddress"
depends="email">
<arg0 key="prompt.replyToAddress"/>
</field>
<field property="username"
depends="required">
<arg0 key="prompt.username"/>
</field>
<field property="password2"
depends="required, requireif"
bundle="alternate">
<arg0 key="prompt.password2"/>
<arg1 key="error.password.match"/>
<var>
<var-name>test</var-name>
<var-value>((password2 == password) and (*this* != null))</var-value>
</var>
</field>
</form>
This is the validation-rules-xml. You must make sure the class, org.apache.struts.validator.FieldChecks has the validateRequired method. This class is found in struts.jar.
<form-validation>
<global>
<validator name="required"
classname="org.apache.struts.validator.FieldChecks"
method="validateRequired"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionMessages,
javax.servlet.http.HttpServletRequest"
msg="errors.required"/>
<validator name="requiredif"
classname="org.apache.struts.validator.FieldChecks"
method="validateRequiredIf"
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"
msg="errors.required"/> -
Struts validation requiredif[ Go to top ]
- Posted by: Hideki Mae
- Posted on: January 04 2005 15:49 EST
- in response to M. Ho
I am having a similar problem with requiredif. I checked struts.jar and I do have RequireIf() in it. Is it supposed to get a javaScript generated in validator-rules.xml and in the web page? If it doesn't is there something wrong with my jar file?
Thanks. -
Struts validation requiredif[ Go to top ]
- Posted by: Kishore Senji
- Posted on: January 14 2005 01:52 EST
- in response to Hideki Mae
I am having a similar problem with requiredif. I checked struts.jar and I do have RequireIf() in it. Is it supposed to get a javaScript generated in validator-rules.xml and in the web page? If it doesn't is there something wrong with my jar file?Thanks.
requiredIf has been replaced with validWhen -
Does validation generate a javascript alert?[ Go to top ]
- Posted by: fl z
- Posted on: March 22 2005 22:24 EST
- in response to Kishore Senji
I am having a similar problem with requiredif. I checked struts.jar and I do have RequireIf() in it. Is it supposed to get a javaScript generated in validator-rules.xml and in the web page? If it doesn't is there something wrong with my jar file?Thanks.
requiredIf has been replaced with validWhen
It displayed error message from ActionError for me when validation fails. -
validwhen and requiredif do not work![ Go to top ]
- Posted by: Meena Venkat
- Posted on: November 11 2009 09:12 EST
- in response to fl z
I have been try validwhen and requiredif but am unable to get my validation right. I have a boolean value based on which i decide if values in a dropdown are needed or not for the submit. can someone help me with this? -
Re: Struts validation requiredif[ Go to top ]
- Posted by: Meena Venkat
- Posted on: November 11 2009 09:14 EST
- in response to Hideki Mae
I have tried your sample code too but it doesn seem to help me. Either it alerts incorreclty or doesn alert at all.