Just let the required attribute of each field check for the passed value of the other fields. The presented value is available in the parameter map #{param} client identifier as a key.
Here is an example run:
<h:form id="form"> <h:inputText id="field1" ... required="#{empty param['form:field2'] and empty param['form:field3']}" /> <h:inputText id="field2" ... required="#{empty param['form:field1'] and empty param['form:field3']}" /> <h:inputText id="field3" ... required="#{empty param['form:field1'] and empty param['form:field2']}" /> </h:form>
It becomes even more ugly as the number of fields increases.
Alternatively, you can use OmniFaces <o:validateOneOrMore> :
<h:form id="form"> <h:inputText id="field1" ... /> <h:inputText id="field2" ... /> <h:inputText id="field3" ... /> <o:validateOneOrMore id="oneOrMore" components="field1 field2 field3" /> <h:message for="oneOrMore" /> </h:form>
Note that performing validation in an action method is a poor design. To do this, you should use standard JSF validation tools such as requiered , validator , <f:validator> and / or <f:validateXxx> .
source share