title: Primefaces - how to update dynamic a .xhtml form from another form
body: <p>I would like when i click the link for cancelling a request my form which contains the form with commandLink to update dynamically (because this record should not be visible in this form anymore). Here is my code:</p>
  
  <pre><code>&lt;h:form id = "form"&gt;
          &lt;p:dataGrid id = "dataGrid" value="#{userRequestBean.userActiveRequests}" columns="1"
              var="userActiveRequest" selection="#{userRequestBean.request}"
              rowKey="#{userActiveRequest.id}"&gt;
              &lt;f:facet name="header"&gt;
              My requests
          &lt;/f:facet&gt;
  
              &lt;h:panelGrid id="panelGrid"&gt;
                  &lt;h:outputText value="#{userActiveRequest.title.toUpperCase()}" /&gt;
                  &lt;h:outputText value="#{userActiveRequest.description}" /&gt;
  
                  &lt;h:form rendered="#{not empty userActiveRequest.hiredAgency}"&gt;
                      &lt;h:commandLink
                          value="Details for agency #{userActiveRequest.hiredAgency.tUser.name}"
                          action="agencyDetail?faces-redirect=true"&gt;
                          &lt;f:setPropertyActionListener target="#{agencyBean.tAgency}"
                              value="${userActiveRequest.hiredAgency}" /&gt;
                      &lt;/h:commandLink&gt;
                  &lt;/h:form&gt;
  **//HERE IS THE COMMANDLINK WHICH I MENTIONED**
                  &lt;h:form rendered="#{empty userActiveRequest.hiredAgency}"&gt;
                      To cancel, click &lt;p:commandLink
                          value="HERE" action="#{userRequestBean.cancelRequest()}"
                          update = "form:dataGrid:panelGrid"&gt;
                          &lt;f:setPropertyActionListener target="#{userRequestBean.request}"
                              value="${userActiveRequest}" /&gt;
                      &lt;/p:commandLink&gt;
                  &lt;/h:form&gt;
  
                  &lt;p:commandButton value="Details"
                      action="userRequestDetails?faces-redirect=true"&gt;
                      &lt;f:setPropertyActionListener target="#{userRequestBean.request}"
                          value="${userActiveRequest}" /&gt;
                  &lt;/p:commandButton&gt;
              &lt;/h:panelGrid&gt;
          &lt;/p:dataGrid&gt;
      &lt;/h:form&gt;
  </code></pre>
  
  <p><strong>ADDED:</strong>
  Part of the Java class:</p>
  
  <pre><code>private List&lt;TRequest&gt; userActiveRequests; // + get and set methods
  
      public UserRequestBean(){
          EntityManager em = HibernateUtil.getEntityManager();
          Query query = em.createQuery("select r " +
                  "from TUser u join u.userRequests r where u.id = :userId and r.isActive = 'Y'");
          query.setParameter("userId", Long.valueOf(11));
          userActiveRequests = query.getResultList();
      }
  
      public void cancelRequest (){
          EntityManager em = HibernateUtil.getEntityManager();
          em.getTransaction().begin();
          request.setIsCancelled(true);
          request.setIsActive(false);
          em.merge(request);
          em.getTransaction().commit();
          //remove the object from the List
          userActiveRequests.remove(request);
      }
  </code></pre>