title: JSF events do not fire the first time screen elements are used, but work fine subsequently
body: <p>Simple piece of code below, yet it doesn't work as expected. The button only starts working the 2nd time I press it (displays the expected error message). The first time it does nothing.</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"&gt;
  
  &lt;h:head&gt;
     &lt;title&gt;Some Title&lt;/title&gt;
  &lt;/h:head&gt;
  
  &lt;h:body&gt;
     &lt;h:form&gt;
        &lt;p:panelGrid id="panel" columns="2" border="0" cellpadding="10" cellspacing="1"&gt;      
           &lt;p:outputLabel value="Enter Username" /&gt;
           &lt;p:inputText id="username" size="20" label="UserName" required="true"&gt;
              &lt;f:validateLength for="username" minimum="5" maximum="20" /&gt;            
           &lt;/p:inputText&gt;
  
           &lt;p:outputLabel value="Test" /&gt;
           &lt;p:commandButton id="submit" value="Submit" action="result"/&gt;
        &lt;/p:panelGrid&gt;
        &lt;p:messages autoUpdate="true" /&gt;
     &lt;/h:form&gt;
  &lt;/h:body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><br />
  If I remove the validation altogether and just try to make a call to a backing Bean, I get the same result. After loading the page, pressing the button the 1st time does nothing. Pressing it subsequent times works fine.</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"&gt;
  
  &lt;h:head&gt;
     &lt;title&gt;Some Title&lt;/title&gt;
  &lt;/h:head&gt;
  
  &lt;h:body&gt;
     &lt;h:form&gt;
        &lt;p:panelGrid id="panel" columns="2" border="0" cellpadding="10" cellspacing="1"&gt;      
           &lt;p:outputLabel value="Enter Username" /&gt;
           &lt;p:inputText id="username" size="20" label="UserName" /&gt;
  
           &lt;p:outputLabel value="Test" /&gt;
           &lt;p:commandButton value="Continue" actionListener="#{signupBean.signup}" icon="ui-icon-check" /&gt;
        &lt;/p:panelGrid&gt;
        &lt;p:messages autoUpdate="true" /&gt;
     &lt;/h:form&gt;
  &lt;/h:body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><br />
  Here is another test, with 2 DropDown controls. Changing the value on the first one is supposed to update the available options on the same one. After loading the page, the first time I select an item on Country does nothing on Province. Thereafter it works fine.</p>
  
  <pre><code>&lt;p:selectOneMenu id="country" value="#{signupBean.countryId}" style="width:200px"&gt;
      &lt;p:ajax update="province" /&gt;
      &lt;f:selectItem itemLabel="Select Country" itemValue="0" noSelectionOption="true" /&gt;
      &lt;f:selectItems value="#{countriesBean.countries}" var="country" itemValue="#{country.id}" itemLabel="#{country.name}" /&gt;
  &lt;/p:selectOneMenu&gt;
  
  &lt;p:selectOneMenu id="province" value="#{signupBean.provinceId}" style="width:200px"&gt;
      &lt;f:selectItem itemLabel="Select State or Province" itemValue="0" noSelectionOption="true" /&gt;
      &lt;f:selectItems value="#{signupBean.provinces}" var="province" itemValue="#{province.provinceId}" itemLabel="#{province.name}" /&gt;
  &lt;/p:selectOneMenu&gt;
  </code></pre>
  
  <p><br/><br/></p>
  
  <p>Here's the request/response cycles for the 1st Test illustrated above:
  <br/><br/>
  <b>When page first loads</b><br/></p>
  
  <pre><code>Request
  GET                 /PictabiteServer/faces/pages/venues/zzbTest.xhtml HTTP/1.1
  Host:               localhost:8080
  Accept:             text/html,application/xhtml+xml,application/xml;q=0.9,*/ *;q=0.8
  Cookie:             SESSIONID=6b770d215805cacdf9f6a1d0d29c; has_js=1
  User-Agent:         Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/600.8.9 (KHTML, like Gecko) Version/8.0.8 Safari/600.8.9
  Accept-Language:    en-us
  Accept-Encoding:    gzip, deflate
  Connection:         keep-alive
  
  Response
  HTTP/1.1            200 OK
  X-Powered-By:       JSF/2.0
  Content-Type:       text/html;charset=UTF-8
  Content-Length:     2679
  Date:               Tue, 20 Oct 2015 19:56:24 GMT
  </code></pre>
  
  <p><br><br>
  <b>First click (when nothing happens)</B>
  <br></p>
  
  <pre><code>Request
  POST                /PictabiteServer/faces/pages/venues/zzbTest.xhtml HTTP/1.1
  Host:               localhost:8080
  Accept:             application/xml, text/xml, */ *; q=0.01
  Faces-Request:      partial/ajax
  X-Requested-With:   XMLHttpRequest
  Accept-Encoding:    gzip, deflate
  Accept-Language:    en-us
  Content-Type:       application/x-www-form-urlencoded; charset=UTF-8
  Origin:             http://localhost:9181
  Content-Length:     188
  User-Agent:         Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/600.8.9 (KHTML, like Gecko) Version/8.0.8 Safari/600.8.9
  Referer:            http://localhost:9181/PictabiteServer/faces/pages/venues/zzbTest.xhtml
  Connection:         keep-alive
  Cookie:             SESSIONID=6b770d215805cacdf9f6a1d0d29c; has_js=1
  Payload:            javax.faces.partial.ajax=true&amp;javax.faces.source=form%3Asubmit&amp;javax.faces.partial.execute=%40all&amp;javax.faces.partial.render=form&amp;form%3Asubmit=form%3Asubmit&amp;form%3Ausername=&amp;form_SUBMIT=1
  
  Response
  HTTP/1.1            200 OK
  X-Powered-By:       JSF/2.0
  Cache-Control:      no-cache
  Content-Type:       text/xml;charset=UTF-8
  Content-Length:     2534
  Date:               Tue, 20 Oct 2015 19:59:33 GMT
  Payload:            
  &lt;?xml version='1.0' encoding='utf-8'?&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;![CDATA[
      &lt;form action="/PictabiteServer/faces/pages/venues/zzbTest.xhtml" enctype=
      "application/x-www-form-urlencoded" id="form" method="post" name="form"&gt;
          &lt;table class="ui-panelgrid ui-widget" id="form:panel" role="grid"&gt;
              &lt;tbody&gt;
                  &lt;tr class="ui-widget-content" role="row"&gt;
                      &lt;td class="ui-panelgrid-cell" role="gridcell"&gt;&lt;label class=
                      "ui-outputlabel ui-widget" id="form:j_idt6"&gt;Enter
                      Username&lt;/label&gt;&lt;/td&gt;
                      &lt;td class="ui-panelgrid-cell" role="gridcell"&gt;
                          &lt;input aria-required="true" class=
                          "ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all"
                          id="form:username" name="form:username" size="20" type=
                          "text"&gt;
                          &lt;script id="form:username_s" type="text/javascript"&gt;
                          &lt;!--
                          PrimeFaces.cw("InputText","widget_form_username",{id:"form:username",widgetVar:"widget_form_username"});
                          //--&gt;
                          &lt;/script&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr class="ui-widget-content" role="row"&gt;
                      &lt;td class="ui-panelgrid-cell" role="gridcell"&gt;&lt;label class=
                      "ui-outputlabel ui-widget" id=
                      "form:j_idt7"&gt;Test&lt;/label&gt;&lt;/td&gt;
                      &lt;td class="ui-panelgrid-cell" role="gridcell"&gt;
                          &lt;button class=
                          "ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
                          id="form:submit" name="form:submit" onclick=
                          "PrimeFaces.ab({s:&amp;quot;form:submit&amp;quot;,u:&amp;quot;form&amp;quot;});return false;"
                          type="submit"&gt;&lt;span class=
                          "ui-button-text ui-c"&gt;Submit&lt;/span&gt;&lt;/button&gt;
                          &lt;script id="form:submit_s" type="text/javascript"&gt;
                          &lt;!--
                          PrimeFaces.cw("CommandButton","widget_form_submit",{id:"form:submit",widgetVar:"widget_form_submit"});
                          //--&gt;
                          &lt;/script&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/tbody&gt;
          &lt;/table&gt;&lt;!-- &lt;p:messages autoUpdate="true" /&gt; --&gt;
          &lt;div aria-live="polite" class="ui-message" id="form:j_idt9"&gt;
          &lt;/div&gt;&lt;input name="form_SUBMIT" type="hidden" value="1"&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;]]&gt;
      &lt;![CDATA[xx0mj9nLEgqpT1Qzy+C+EOPBDpgzlWfrR47DK7Jrk7FQOmB3AoP9QejbqT9qxvCnkXXkd9atuFv4K78lufbk+qH+bNArqpnjf2p48aHz8pe5gGbbmv2RB2LF1jauia2rP9UbsDKgFRmy6CrlGy4H70h40u4Ys9Jvhc83utraiA8kELR5Hc+7lnaF3ABTt0Xnhj2jAT4QzPyCHCEKyZpU3OeN9eW5JhDYK18U0uiND4OYcbHZsfUsphazJZ7q9/dv83QA3X6Wx2CGo9XlenaiFdzRi6btnXaost+LfHr9Yd8VCTQrImmR21i9nQLNiujQAiEPEbcz3cbWOTUGbrUfMFIYm3GaFPyXZAZmqF3OPyFpX1sd0IJm31IYm3GaFPyXi1fDUjlkMX7da9AALtf+yr7cGAfLWthbyDplp3xbCvAz/olFB/apmqkmXyE6TJMSP+taaAhNDdsDz6QF27UCq1IEVl62P6zkVdR1WkREh/hQluZ6xcOFj93EqzKxJglgJqEsXAutHGNe+tgcBumIonsWVDKDN31s9HwjLytEUcsF21bCgL+z9zBxDWrwLp2CG6jM+1PmBH35HiPVcEjla3iU2eV2fgNhn8FvRsM3TkydodlIc1eGpCSb2eGxH8HL/87IeMdlt0bEULSyjE+YAjDPhT3+KVpjqwaz1b7z9H2Nh5Hllsp+A5qJGzg=]]&gt;
      &lt;title&gt;&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><br><br><br>
  <b>Second click (when it works)</b>
  <br></p>
  
  <pre><code>Request
  POST                /PictabiteServer/faces/pages/venues/zzbTest.xhtml HTTP/1.1
  Host:               localhost:8080
  Accept:             application/xml, text/xml, */ *; q=0.01
  Faces-Request:      partial/ajax
  X-Requested-With:   XMLHttpRequest
  Accept-Encoding:    gzip, deflate
  Accept-Language:    en-us
  Content-Type:       application/x-www-form-urlencoded; charset=UTF-8
  Origin:             http://localhost:9181
  Content-Length:     951
  User-Agent:         Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/600.8.9 (KHTML, like Gecko) Version/8.0.8 Safari/600.8.9
  Referer:             http://localhost:9181/PictabiteServer/faces/pages/venues/zzbTest.xhtml
  Connection:         keep-alive
  Cookie:             SESSIONID=6b770d215805cacdf9f6a1d0d29c; has_js=1
  Payload:            javax.faces.partial.ajax=true&amp;javax.faces.source=form%3Asubmit&amp;javax.faces.partial.execute=%40all&amp;javax.faces.partial.render=form&amp;form%3Asubmit=form%3Asubmit&amp;form%3Ausername=&amp;form_SUBMIT=1&amp;javax.faces.ViewState=xx0mj9nLEgqpT1Qzy%2BC%2BEOPBDpgzlWfrR47DK7Jrk7FQOmB3AoP9QejbqT9qxvCnkXXkd9atuFv4K78lufbk%2BqH%2BbNArqpnjf2p48aHz8pe5gGbbmv2RB2LF1jauia2rP9UbsDKgFRmy6CrlGy4H70h40u4Ys9Jvhc83utraiA8kELR5Hc%2B7lnaF3ABTt0Xnhj2jAT4QzPyCHCEKyZpU3OeN9eW5JhDYK18U0uiND4OYcbHZsfUsphazJZ7q9%2Fdv83QA3X6Wx2CGo9XlenaiFdzRi6btnXaost%2BLfHr9Yd8VCTQrImmR21i9nQLNiujQAiEPEbcz3cbWOTUGbrUfMFIYm3GaFPyXZAZmqF3OPyFpX1sd0IJm31IYm3GaFPyXi1fDUjlkMX7da9AALtf%2Byr7cGAfLWthbyDplp3xbCvAz%2FolFB%2FapmqkmXyE6TJMSP%2BtaaAhNDdsDz6QF27UCq1IEVl62P6zkVdR1WkREh%2FhQluZ6xcOFj93EqzKxJglgJqEsXAutHGNe%2BtgcBumIonsWVDKDN31s9HwjLytEUcsF21bCgL%2Bz9zBxDWrwLp2CG6jM%2B1PmBH35HiPVcEjla3iU2eV2fgNhn8FvRsM3TkydodlIc1eGpCSb2eGxH8HL%2F87IeMdlt0bEULSyjE%2BYAjDPhT3%2BKVpjqwaz1b7z9H2Nh5Hllsp%2BA5qJGzg%3D
  
  Response
  HTTP/1.1            200 OK
  X-Powered-By:       JSF/2.0
  Cache-Control:      no-cache
  Content-Type:       text/xml;charset=UTF-8
  Content-Length:     3013
  Date:               Tue, 20 Oct 2015 20:05:12 GMT
  Payload:            
  &lt;?xml version='1.0' encoding='utf-8'?&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;![CDATA[    &lt;form action="/PictabiteServer/faces/pages/venues/zzbTest.xhtml" enctype=
      "application/x-www-form-urlencoded" id="form" method="post" name="form"&gt;
          &lt;table class="ui-panelgrid ui-widget" id="form:panel" role="grid"&gt;
              &lt;tbody&gt;
                  &lt;tr class="ui-widget-content" role="row"&gt;
                      &lt;td class="ui-panelgrid-cell" role="gridcell"&gt;&lt;label class=
                      "ui-outputlabel ui-widget" id="form:j_idt6"&gt;Enter
                      Username&lt;/label&gt;&lt;/td&gt;
                      &lt;td class="ui-panelgrid-cell" role="gridcell"&gt;
                          &lt;input aria-required="true" class=
                          "ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all ui-state-error"
                          id="form:username" name="form:username" size="20" type=
                          "text" value=""&gt;
                          &lt;script id="form:username_s" type="text/javascript"&gt;
                          &lt;!--
                          PrimeFaces.cw("InputText","widget_form_username",{id:"form:username",widgetVar:"widget_form_username"});
                          //--&gt;
                          &lt;/script&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr class="ui-widget-content" role="row"&gt;
                      &lt;td class="ui-panelgrid-cell" role="gridcell"&gt;&lt;label class=
                      "ui-outputlabel ui-widget" id=
                      "form:j_idt7"&gt;Test&lt;/label&gt;&lt;/td&gt;
                      &lt;td class="ui-panelgrid-cell" role="gridcell"&gt;
                          &lt;button class=
                          "ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
                          id="form:submit" name="form:submit" onclick=
                          "PrimeFaces.ab({s:&amp;quot;form:submit&amp;quot;,u:&amp;quot;form&amp;quot;});return false;"
                          type="submit"&gt;&lt;span class=
                          "ui-button-text ui-c"&gt;Submit&lt;/span&gt;&lt;/button&gt;
                          &lt;script id="form:submit_s" type="text/javascript"&gt;
                          &lt;!--
                          PrimeFaces.cw("CommandButton","widget_form_submit",{id:"form:submit",widgetVar:"widget_form_submit"});
                          //--&gt;
                          &lt;/script&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/tbody&gt;
          &lt;/table&gt;&lt;!-- &lt;p:messages autoUpdate="true" /&gt; --&gt;
          &lt;div aria-live="polite" class=
          "ui-message ui-message-error ui-widget ui-corner-all" id="form:j_idt9"&gt;
              &lt;span class="ui-message-error-icon"&gt;&lt;/span&gt;&lt;span class=
              "ui-message-error-detail"&gt;UserName: Validation Error: Value is
              required.&lt;/span&gt;
          &lt;/div&gt;&lt;input name="form_SUBMIT" type="hidden" value="1"&gt;
      &lt;/form&gt;]]&gt;
      &lt;![CDATA[xx0mj9nLEgqpT1Qzy+C+EOPBDpgzlWfrR47DK7Jrk7FQOmB3AoP9QejbqT9qxvCnkXXkd9atuFv4K78lufbk+qH+bNArqpnjf2p48aHz8pe5gGbbmv2RB2LF1jauia2rP9UbsDKgFRmy6CrlGy4H70h40u4Ys9Jvhc83utraiA8kELR5Hc+7lnaF3ABTt0Xnhj2jAT4QzPyCHCEKyZpU3OeN9eW5JhDYK18U0uiND4OYcbHZsfUsphazJZ7q9/dv83QA3X6Wx2CGo9XlenaiFdzRi6btnXaost+LfHr9Yd8VCTQrImmR21i9nQLNiujQM5JcCsg7JifdpiiuudmDswM/MBwgukOv29N5DulgW+Z8ZyzewXf59dBIejAk2ZA+yb4xK9rOeXQ+SmuXGQbEfmbL/M1mMQu9GLpWVz6T4vZQugK/IIzu/Xy9ZjaAGADKs6ikCgHJhHUuqMaYc3MCAE9DFXz/6oBbsTNk6gtMP222ZCEkYXzli1762BwG6Yii0JIWxUiD7I/37LHdN9NM2Ub4coNHfQyFw8jVus8EplV0URb5c7a0dst0JW0r2vh9sSqzrFMWqUHrz1MXfpWQcN3AlYb+If9sZgYS18sybSXN9KbwxaTpn2/FhykQZprHRb/ml3JS0kZAtQQVEQx/t7tEHhQT34DPREmQu0CWZ+PpBho06WB+WB0+O+5CyHzCEVP8E7PJ9WLnxxE4aVLxmClp1ON28Jf3soqhmkQVOibZPAypHAaNzdg/H5kzgWHzzwlZxgjpi7kwd2HFRT3UX8d0432oRunudvnluvpwXjon8JQ4K5Ts007SHgkdqhpz6GUGEAXqUzHtP5AAFrLC0eAQhPCX1OtL/9+LytYXyzl9caQyPBcrT9Lpbl3AeHL1rlV15A==]]&gt;
      &lt;title&gt;&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      {"validationFailed":true}
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I'm on Glassfish 3.1.2, Mojarra 2.1.9, PrimeFaces 5.2</p>
  
  <p>Thanks!</p>