I have one form with several components, some of them have their own validations and/or are mandatory. Then I also have several selectOneMenu components that have the same three selectItem elements in their lists. I have defined three commandButton in order to select the same values for all the lists (one commandButton per possible value).
The JSF section
<table>
<tr>
<td>
<h:outputText value="ID:" />
</td>
<td>
<h:inputText value="#{MyClass.id}" id="inTxt_id" required="true">
<f:validator validatorId="CheckIDPattern" />
</h:inpuText>
<h:message for="inTxt_id" errorClass="error" />
</td>
</tr>
</table>
<table>
<tr>
<td>
<h:commandButton value="Select all opt1" action="#{MyClass.selectOpt1}" />
<h:commandButton value="Select all opt2" action="#{MyClass.selectOpt2}" />
<h:commandButton value="Select all opt3" action="#{MyClass.selectOpt3}" />
</td>
</tr>
<tr>
<td>
<h:outputText value="List 1:" />
</td>
<td>
<h:selectOneMenu value="#{MyClass.list1Val}">
<f:selectItems value="#{MyClass.listOfOptions}" />
</h:selectOneMenu>
</td>
<tr>
<td>
<h:outputText value="List 2:" />
</td>
<td>
<h:selectOneMenu value="#{MyClass.list2Val}">
<f:selectItems value="#{MyClass.listOfOptions}" />
</h:selectOneMenu>
</td>
</tr>
<tr>
//Many other selectOneMenu components...
</tr>
</table>
<h:commandButton action="#{MyClass.saveLists}" value="Submit" />
MyClass.java
public String selectOpt1(){
this.list1Val = 1;
this.list2Val = 1;
//...
return "";
}
//The same idea for selectOpt2 and selectOpt3.
In this context, if my user presses one of my "select all" buttons without filling the ID inputText, it receives the error message, but I don't want it because I suppose they haven't finished filling the form. I just want the validations to be executed when the user presses the "Save Lists" button.
I've tried adding immediate="true" to my "select all" buttons, it works but it doesn't update the view from model and then the user doesn't see the values have changed... so it really doesn't work.
What do I want to achieve? I just want the validations to be performed when the last button (submit). So my user could use these "select all" buttons without filling previously the mandatory components.
I hope you understand my context. Feel free to ask for any clarification. Thanks in advance.