File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

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.

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: 17421

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 agree. Here's the link:
subject: Required text field
It's not a secret anymore!