How to validate if at least one of multiple input fields is entered?

后端 未结 2 1473
遇见更好的自我
遇见更好的自我 2020-12-07 03:05

I have a form with 3 fields, and submit button. when button clicked, if none is entered in 3 fields, throw validation message. If any one of the 3 fields are entered process

2条回答
  •  天涯浪人
    2020-12-07 03:50

    Just let the required attribute of each field check the presence of the submitted value of the other fields. The submitted value is available in the parameter map #{param} by the client ID as key.

    Here's a kickoff example:

    
        
        
        
    
    

    It gets only more ugly as the amount of fields grows.

    Alternatively, you can use OmniFaces :

    
        
        
        
    
        
        
    
    

    Please note that performing validation in action method is bad design. You should use the standard JSF validation facilities for this such as requiered, validator, and/or .

提交回复
热议问题