Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts validation help needed....

 
K Amin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
K Amin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
K Amin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic