Hi
In the validator method (in the backing bean) add a message for the hidden
component and set it as invalid.
public void validateDate(FacesContext context, UIComponent toValidate,
Object value) {
FacesMessage facesMessage = null;
if (!validDate) {
facesMessage = new
FacesMessage(FacesMessage.SEVERITY_ERROR,"message summary","message detail");
context.addMessage(toValidate.getClientId(context),facesMessage);
((UIInput)toValidate).setValid(false);
}
}
HIH.
Balaji
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Thursday, 2 February 2006 2:31 PM
To: 'MyFaces Discussion'
Subject: validating multiple fields
I want to create a validator that works on multiple fields. Basically,
if one is entered the other two must be entered. If it set the validator
on any one field and it isn't entered, the validator is not run, so I must
put it on all three fields. Then I need to worry about if the error message
has already been set by a previous validator, among other things. In the
book Core JavaServer Faces, they mention the alternative approach below, but
I can't get it to work. No matter what I put in the value attribute, the
validator is not run. What do I need to do for "It is essential that you
supply some field value"?
Thanks,
Lance
==========================================================================
An alternative approach is to attach the validator to a hidden input field
that comes after all other fields on the form.
<h:inputHidden id="datecheck" validator="#{bb.validateDate}"
value="needed"/>
The hidden field is rendered as a hidden HTML input field. When the field
value is posted back, the validator kicks in. (It is essential that you
supply some field value. Otherwise, the component
value is never updated.) With this approach, the validation function is more
symmetrical since all other form components already have their local values
set.
This correspondence is for the named persons only.
It may contain confidential or privileged information or both.
No confidentiality or privilege is waived or lost by any mis transmission.
If you receive this correspondence in error please delete it from your system
immediately and notify the sender.
You must not disclose, copy or relay on any part of this correspondence, if you
are not the intended recipient.
Any opinions expressed in this message are those of the individual sender
except where the sender expressly,
and with the authority, states them to be the opinions of the Department of
Emergency Services, Queensland.