aspose file tools*
The moose likes Struts and the fly likes Problem using Validation: validwhen condition not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problem using Validation: validwhen condition not working" Watch "Problem using Validation: validwhen condition not working" New topic
Author

Problem using Validation: validwhen condition not working

Sarah ss
Greenhorn

Joined: Jul 28, 2006
Posts: 3
Hey guys

I've spend the last 4 hours trying this out - but no luck. If someone can help me out, I would really really appreciate it.

I have a simple page with two buttons.
searchByZipButton and searchByStateButton.

They are defined in my ActionForm as ImageButtonBean type.
I use the isSelected method to determine which button was clicked.

Now in validation.xml


I dont know how to specify the condition that check if zip code is entered only when searchByZipButton is clicked. Similarly check if state is entered only when searchByStateButton is clicked.

These are image button beans. So I dont know how to call their isSelected method in validation.xml.

Please help
Thanks
Sarah
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Try this:
<var-name>test</var-name>
<var-value>((!searchByZipButton.selected) or (*this* != null))</var-value>

See the section entitled "Designing Complex Validations with validwhen" in this link.

Note: This type of validation rule will not work in client-side validation.
[ July 30, 2006: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
Sarah ss
Greenhorn

Joined: Jul 28, 2006
Posts: 3
hey merill
thanks for your suggestion. I tried that but i'm getting error



i think we can access only properties like that and selected is not a property of ImageButtonBean.

Appreciate your input
thanks
sarah
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Oh well, it was worth a shot.

Looks like your options are:

1-override the validate() method of your ActionForm. Manually code the logic for this validation, then call super.validate() to handle the validation framework validations.

2-Create a custom validation rule that will handle this situation.

This link shows you how to create a custom validator rule.
[ July 30, 2006: Message edited by: Merrill Higginson ]
Ish Ash
Greenhorn

Joined: Jul 30, 2006
Posts: 3
This may not be the exact way to do this, but it will definitely work.

Try it out and let me know if it doesnt work



Good Luck
--IshAsh
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I did think of one method that will work. Create a "buttonPressed" property for your ActionForm and put it as a hidden field in your JSP. Use JavaScript to set this text field to either "byZip" or "byState" when one or the other button is clicked.

You can then code the following as your condition:

(buttonPressed != 'byZip') or (*this* != null)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem using Validation: validwhen condition not working