Mike Kienenberger wrote:
On 4/4/06, Richard Wallace <[EMAIL PROTECTED]> wrote:
For the
validation if a user doesn't enter a response, we want error messages at
the top of the page that say:

Questions 1, 3, and 7 have not been answered.

So, I've been thinking about what the best way to do that is.  The best
thing that I can think of is to not use the required attribute and
instead use a custom required validator to put some error object in a
form specific list of validation errors.  Then have a JSF component that
is similar to the messages component - it shouldn't extend it because I
want form specific validation not page specific - that checks if there
are any errors in the validation error list and creates appropriate
message(s).

You do want to use the required attribute.   Validators are not
triggered if the value is null, so you can't make a standard required
validator.   It is possible to simulate a custom required validator
(see http://wiki.apache.org/myfaces/OptionalValidationFramework), but
it isn't going to help you in any way
How so?
and it doesn't fit in well with JSF.
I'm not sure I really care too much about "fitting in" with JSF in regards to validation. I just want something that works.
Instead, you want to generate standard required validation messages,
then create a custom renderer for the messages component that
consolidates each of these messages into something else, probably by a
specific id pattern.    I also think you'd be better off extending the
existing messages renderer than creating it yourself.

Sounds like a hack to get around a poor validation system. Is there any way to completely replace the JSF validation process with something more flexible? I mean, honestly, this is a pretty simple use case that is extremely difficult to implement. I have to wonder why the required attribute is treated as a special case as well. Validation in JSF seems to be just a mess. I really like JSF overall, but anytime I start thinking about doing any validation I have to take a couple of shots of whiskey and bite down on something hard to try and forget about the pain.
The second form I'm trying to work with is a user registration form.  On
this form the user either enters a certificate number that will allow
them to sign up or they enter their credit card information.  Basically,
if the certificate is there then the credit card information doesn't
matter.  But, if the certificate isn't present then the credit card
information is required.  How should I handle this scenario?  Just add
the extra validation code in my backing bean so that when the form is
submitted it does all the checking?  What do you all think?

Yes, I think the best bet is to make neither component required, but
do certificate/credit card validation on each component as normal.

Then in your submit action, check that one-and-only-one of the
components have a  non-null value.

Reply via email to