title: handle edit action in a data table
body: <p>I have a form with 3 input fields and two command buttons(Submit and Cancel). Once the user submits the form, the information should be populated in the data table below with 3 columns.There is also a action column with EDIT and DELETE command links for each row inserted. On click of EDIT, the information for that record needs to be populated to the form above and then if the form is submitted, check if the record already exists. If the record doesn't exists, then add it to the list.</p>
  
  <p>XHTML1 
      
                      
                          FirstName:
                          </p>
  
  <pre><code>                    &lt;h:outputLabel&gt;LastName:&lt;/h:outputLabel&gt;
                      &lt;h:inputText id="lastName" value="#{form.lastName}"/&gt;
  
                      &lt;h:outputLabel&gt;MiddleName:&lt;/h:outputLabel&gt;
                      &lt;h:inputText id="middleName" value="#{form.middleName}" /&gt;
  
                      &lt;h:commandButton value="Cancel" action="#{formBacking.cancel}" immediate="true"&gt;&lt;/h:commandButton&gt;
                      &lt;h:commandButton value="Submit" action="#{formBacking.submit}"&gt;&lt;/h:commandButton&gt;
  
                  &lt;/h:panelGrid&gt;
  
              &lt;/h:form&gt;
  </code></pre>
  
  <p>XHTML2
          
              <h2>
                  User Details
              </h2>
              </p>
  
  <pre><code>            &lt;h:column&gt;
                  &lt;f:facet name="header"&gt;FirstName&lt;/f:facet&gt;
                  &lt;h:outputText value="#{userDetails.fname}" /&gt;
              &lt;/h:column&gt;
  
              &lt;h:column&gt;
                  &lt;f:facet name="header"&gt;LastName&lt;/f:facet&gt;
                  &lt;h:outputText value="#{userDetails.lname}" /&gt;
              &lt;/h:column&gt;
  
              &lt;h:column&gt;
                  &lt;f:facet name="header"&gt;MiddleName&lt;/f:facet&gt;
                  &lt;h:outputText value="#{userDetails.mName}" /&gt;
              &lt;/h:column&gt;
  
              &lt;h:column&gt;
                  &lt;f:facet name="header"&gt;Action&lt;/f:facet&gt;
                  &lt;h:commandLink
                      action="#{formBacking.editUser(userDetails)}"
                      value="Edit" /&gt;
                  &lt;h:commandLink
                      action="#{formBacking.deleteUser(userDetails)}"
                      value="Delete" /&gt;
              &lt;/h:column&gt;
  
          &lt;/h:dataTable&gt;
      &lt;/h:form&gt;
  
   Form.java
      @Managed Bean
      @ViewScoped
      private String firstName = "";
      private String lastName = "";
      private String middleName = "";
      //Setters and getters
  
      UserBacking.java
  
      @ManagedBean
      @ViewScoped
  
      private List&lt;Form&gt; userList = new ArrayList&lt;Form&gt;();
      \\setters and getters
  
      public void submit(){}
      public void cancel(){}
      public void editUser(){}
      public void deleteUser(){}
  
  What would be the best way to handle the edit functionality?
  </code></pre>