aspose file tools*
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


Win a copy of Soft Skills this week in the Jobs Discussion forum!
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: 16303
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Required text field