File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Struts validation help needed.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts validation help needed...." Watch "Struts validation help needed...." New topic
Author

Struts validation help needed....

K Amin
Greenhorn

Joined: Oct 11, 2007
Posts: 8
Hi all,

I have a form that has a dropdowm list. If user picks a specific value from that dropdown list, I need to check another field in the form with a value greater than zero. For all other picks from the dropdown, I don't have to worry. Any suggestion will be very helpfull.

And also I am using client side validation, If any body can suggest me how to check two password field is same or not, that will be great.

Thanks in advance..........
[ October 17, 2007: Message edited by: K Amin ]
John Melton
Ranch Hand

Joined: Aug 17, 2004
Posts: 49
For your first question, get the parameter from the form bean and compare the values to your expected value using the .equals method. If true, then check the other field.
For your second question just use the javascript if field1 == field2, then do something


[url]www.jtmelton.com[/url]
K Amin
Greenhorn

Joined: Oct 11, 2007
Posts: 8
Thanks John.
I know how to compare 2 fields in java script. But the thing I dont know how to use this javascript function with struts validation, cause other fields of the same form is validated by struts validation. Any suggestion will be appreciated. thanks again.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
You may be able to use the validwhen rule for this. For details, see the Struts Validator Guide.
[ October 17, 2007: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
K Amin
Greenhorn

Joined: Oct 11, 2007
Posts: 8
Thanks Merrill,

Yes the password checks is working fine with validwhen. But I am having problem with displaying message in window alert. Here is my code, 1st 3 requied field displays fine in pop-up window, but when it comes to validwhen, it dosn't. Again if both passwords are same it works fine. If anybody can help me, that will be great.

<form name="changePasswordForm">
<field property="oldpassword" depends="required">
<arg0 key="label.oldpassword"/>
</field>
<field property="newpassword" depends="required">
<arg0 key="label.newpassword"/>
</field>
<field property="newpasswordAgain" depends="required,validwhen">
<arg0 key="label.newpasswordAgain" />
<msg name="validwhen" key="Both new password should be same."/>
<var>
<var-name>test</var-name>
<var-value>((newpassword == newpasswordAgain) or (*this* == newpassword))</var-value>
</var>
</field>
</form>

Thanks again....
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Struts validation help needed....
 
Similar Threads
Validation problem with Struts1.2
Reset button & Validation Error
dynamic drop down list
drop down list validation
Hashmap in Struts