myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mike Kienenberger" <mkien...@gmail.com>
Subject Re: Validation questions
Date Tue, 04 Apr 2006 21:52:42 GMT
On 4/4/06, Richard Wallace <rwallace@thewallacepack.net> 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 and it doesn't fit in well with
JSF.

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.

> 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.

Mime
View raw message