• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Validate a textField using Struts Validator

 
Yuvika Sharma
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having problem validating a text field if another text-box is filled.
I ws trying to use requiredif or validwhen methods from validator-rules but it doesnt work. Could someone suggest what I'm doing wrong.
This is the validwhen in Validator-rules.xml
<validator name="validwhen"

classname="org.apache.struts.validator.validwhen.ValidWhen"
method="validateValidWhen"
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.required">

</validator>
This is my Valiadtions.xml entry:

<field
property="conName2"
depends="validwhen">
<arg0 key="SupplierContactsForm.conName2"/>
<var>
<var-name>test</var-name>
<var-value>((location2== null) or (*this* != null))</var-value>
</var>
</field>

ConName2 and location2 are the two textboxes I ahve on my jsp page.
I have all other things in place, the required validations is working on the same page.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65124
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Yuvi Yuvi",

We're pleased to have you here with us on the Ranch, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
Forum Bartender

P.S. Also we have a forum for Struts questions... I'll move this topic there for you.
[ August 06, 2004: Message edited by: Bear Bibeault ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic