This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes JSF and the fly likes Required text field Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSF
Bookmark "Required text field" Watch "Required text field" New topic
Author

Required text field

Higgledy Smith
Ranch Hand

Joined: Mar 07, 2006
Posts: 192

In a form with two text fields, either one is required. For instance, if the Zip Code is supplied, then the address is not required. But if the Zip Code is not supplied then the address is required.

In my code below, I need the company name -OR- the DUNS Number.

How do I code this logic? Here is my form:




Thank you.
higgledy


nitin pokhriyal
Ranch Hand

Joined: May 19, 2005
Posts: 263
You can always have validation in your backend bean before saving.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17033
    
  26

This is a good use for a validator, although none of the stock JSF core validators do this. I think that the MyFaces Extensions Validators may include something that will do the trick, though.

I wrote my own for passwords, where you have 2 password inputs and only if they both match will the action be considered valid.

You CAN do this kind of checking in the action processor, but it's somewhat cleaner not to have to.


An IDE is no substitute for an Intelligent Developer.
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Required text field
 
jQuery in Action, 3rd edition