jQuery in Action, 2nd edition*
The moose likes Struts and the fly likes Validate a textField using Struts Validator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Validate a textField using Struts Validator" Watch "Validate a textField using Struts Validator" New topic
Author

Validate a textField using Struts Validator

Yuvika Sharma
Greenhorn

Joined: Aug 06, 2004
Posts: 2
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

Joined: Jan 10, 2002
Posts: 60737
    
  65

"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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Validate a textField using Struts Validator
 
Similar Threads
Validwhen validator question
Validate a textField using Struts Validator
struts 1.2.7 validation using validwhen
Problems with checkbox using Struts Validation
validwhen not work, even validate double not work