I've got 2 forms that I'm trying to do validation on. One form is an
assessment form, where the user needs to answer each question. 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).
A default implementation of the new messages component could act just
like the existing JSF validation and just pump out messages from
resource properties for the type of control being used. Someone that
wanted more control over the error messages could create a custom
subclass of the messages component that creates one or more messages in
the format they want. So, for my case, instead of having something like:
Question 1 has not been answered.
Question 3 has not been answered.
Question 7 has not been answered.
I can condense it into something more user friendly like at the
beginning of this message.
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?
Thanks for the input,
Rich