title: p:commandButton only works with two clicks (JSF 2.2 Bug?)
body: <p>i'm trying to update (merge) a field from a ListDataModel and I'm experiencing what I think is a bug in Jsf (Mojara) 2.2. The update only works if the PrimeFaces command button is clicked twice. I've read a number of posts on here and tried the solutions but nothing seems to be working:</p>
  
  <p><a href="https://stackoverflow.com/questions/11408130/hcommandbutton-hcommandlink-does-not-work-on-first-click-works-only-on-second">h:commandButton/h:commandLink does not work on first click, works only on second click</a></p>
  
  <p><a href="https://stackoverflow.com/questions/23171637/commandbutton-only-works-on-the-second-click">commandButton only works on the second click</a></p>
  
  <p><a href="https://stackoverflow.com/questions/13878620/pcommandbutton-with-pfiledownload-and-no-ajax-only-works-in-second-click">p:commandButton with p:fileDownload and no ajax only works in second click</a></p>
  
  <p>The list comes from </p>
  
  <pre><code>            &lt;h:form&gt;
                  &lt;p:dataTable value="#{proDocFolBean.selectedProDocs}" var="docs"&gt;
  
  
                      &lt;p:column headerText="Document Name:"&gt;
                          &lt;h:outputText value="#{docs.docName}"/&gt;
                      &lt;/p:column&gt;
  
                      &lt;p:column headerText="Description"&gt;
                          &lt;h:outputText value="#{docs.description}"/&gt;
                      &lt;/p:column&gt;
  
  
  
                      &lt;p:column headerText="Date Created"&gt;
                          &lt;h:outputText value="#{docs.dateCreated}"&gt;
                              &lt;f:convertDateTime pattern="dd-MMM-yyyy" /&gt;
                          &lt;/h:outputText&gt;
                      &lt;/p:column&gt;
  
                      &lt;p:column headerText="Classification"&gt;
                          &lt;h:outputText value="#{docs.classification}"/&gt;
                      &lt;/p:column&gt;
  
                      &lt;p:column&gt;
  ***                        &lt;p:commandLink value="Update" action="#{proDocFolBean.prepareUpdateDoc}"/&gt; ***
  
                      &lt;/p:column&gt;
  
  
                      &lt;p:column&gt;
  
                          &lt;p:commandLink id="downLoadLink" value="Download" ajax="false"&gt;
                              &lt;p:fileDownload value="#{proDocFolBean.downloadFromFolders}" 
                                              contentDisposition="attachment"/&gt;
                          &lt;/p:commandLink&gt;
  ....
                  &lt;/h:form&gt;
  </code></pre>
  
  <p>Clicking the Update link in the above form calls a preparedUpdate method in the bean:</p>
  
  <pre><code>public String prepareUpdateDoc() {
      docToUpdate = selectedProDocs.getRowData();
      selectedId = docToUpdate.getProjectDocId();
      docsFacade.find(selectedId);
  
          return "UpdateProDoc";
  }
  </code></pre>
  
  <p>The above method populates the update form:</p>
  
  <pre><code>&lt;h:outputScript name="js/formbugfix.js" target="head" /&gt; 
                  &lt;p:inputTextarea rows="30" cols="60" value="#{proDocFolBean.docToUpdate.description}" immediate="true"/&gt;
                          &lt;p&gt;
                      &lt;p:commandButton value="Change" action="#{proDocFolBean.updateProjectDoc}"&gt;
                          &lt;!-- &lt;f:ajax execute="@form"/&gt; --&gt;
                      &lt;/p:commandButton&gt;
  </code></pre>
  
  <p>I included a js script although I realize that PF has already fixed view state through embedded js. I thought possibility including a script  as stated in this <a href="https://stackoverflow.com/questions/11408130/hcommandbutton-hcommandlink-does-not-work-on-first-click-works-only-on-second">question</a>.</p>
  
  <p>might solve the problem but it results in the same behavior. </p>
  
  <p>Finally, the form calls the following merge method in the bean:</p>
  
  <pre><code>public String updateProjectDoc() {
      docsFacade.update(docToUpdate);
      return "ProSysHome";
  }
  </code></pre>
  
  <p>If I try to use an h:commandbutton or set ajax to false using the p:commandButton (without the js script), the form is simply refreshed and the updated value is not merged into the database. If i use the p:commandButton on its own, I am able to get the operation working but only after two clicks. This is very odd behavior and would appreciate any help. Thanks in advance!</p>