Note that there are some explanatory texts on larger screens.

plurals
  1. POJSF - Update model values from view before validation
    primarykey
    data
    text
    <p>I have one form with several components, some of them have their own validations and/or are mandatory. Then I also have several <code>selectOneMenu</code> components that have the same three <code>selectItem</code> elements in their lists. I have defined three <code>commandButton</code> in order to select the same values for all the lists (one <code>commandButton</code> per possible value).</p> <p><strong>The JSF section</strong></p> <pre><code>&lt;table&gt; &lt;tr&gt; &lt;td&gt; &lt;h:outputText value="ID:" /&gt; &lt;/td&gt; &lt;td&gt; &lt;h:inputText value="#{MyClass.id}" id="inTxt_id" required="true"&gt; &lt;f:validator validatorId="CheckIDPattern" /&gt; &lt;/h:inpuText&gt; &lt;h:message for="inTxt_id" errorClass="error" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt; &lt;h:commandButton value="Select all opt1" action="#{MyClass.selectOpt1}" /&gt; &lt;h:commandButton value="Select all opt2" action="#{MyClass.selectOpt2}" /&gt; &lt;h:commandButton value="Select all opt3" action="#{MyClass.selectOpt3}" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;h:outputText value="List 1:" /&gt; &lt;/td&gt; &lt;td&gt; &lt;h:selectOneMenu value="#{MyClass.list1Val}"&gt; &lt;f:selectItems value="#{MyClass.listOfOptions}" /&gt; &lt;/h:selectOneMenu&gt; &lt;/td&gt; &lt;tr&gt; &lt;td&gt; &lt;h:outputText value="List 2:" /&gt; &lt;/td&gt; &lt;td&gt; &lt;h:selectOneMenu value="#{MyClass.list2Val}"&gt; &lt;f:selectItems value="#{MyClass.listOfOptions}" /&gt; &lt;/h:selectOneMenu&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; //Many other selectOneMenu components... &lt;/tr&gt; &lt;/table&gt; &lt;h:commandButton action="#{MyClass.saveLists}" value="Submit" /&gt; </code></pre> <p><strong>MyClass.java</strong></p> <pre><code>public String selectOpt1(){ this.list1Val = 1; this.list2Val = 1; //... return ""; } //The same idea for selectOpt2 and selectOpt3. </code></pre> <p>In this context, if my user presses one of my "select all" buttons without filling the ID <code>inputText</code>, 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.</p> <p>I've tried adding <code>immediate="true"</code> 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.</p> <p><strong>What do I want to achieve?</strong> 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.</p> <p>I hope you understand my context. Feel free to ask for any clarification. Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload