• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem using Validation: validwhen condition not working

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Sarah ss
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
reply
    Bookmark Topic Watch Topic
  • New Topic