title: Editing additional info in a dataTable on primeFaces
body: <p>So, I have a dataTable on my page that shows some basic information and a row expansion to show the extra information. I'm trying to create a button/context menu to show a dialog so the user could edit the informations on the table (basic and extra, all in a form) but I'm having trouble in getting this data from the table. When I click the button to show the dialog, it only shows the information of the first row, and not the row I selected. Any ideas? Thank you. Code follows below.</p>
  
  <pre><code> &lt;p:dataTable id="socios" var="socio" value="#{sociosBean.socios}" rowKey="#{socio.id}"   
                           selection="#{sociosBean.socioEscolhido}" selectionMode="single" paginator="true"
                           widgetVar="socios" emptyMessage="Nenhum socio encontrado " filteredValue="#{sociosBean.socioFiltro}" 
                           rows="10" paginatorAlwaysVisible="false"&gt;
          &lt;p:menuitem value ="Editar" update="socios" icon ="ui-icon-search"
                      oncomplete="editar.show();"&gt;
              &lt;f:setPropertyActionListener target="#{sociosBean.socioEditar}" value="#{socio}"/&gt;      
          &lt;/p:menuitem&gt;
  
          &lt;p:menuitem value="Excluir" update="socios" icon="ui-icon-close" onclick="excluir.show();"/&gt;
          &lt;f:facet name="header"&gt;  
              &lt;p:outputPanel&gt;  
                  &lt;h:outputText value="Socios" /&gt;   
              &lt;/p:outputPanel&gt;  
          &lt;/f:facet&gt; 
  
          &lt;p:column style="width:2%"&gt;  
              &lt;p:rowToggler /&gt;  
          &lt;/p:column&gt;  
          &lt;p:column headerText="ID" filterMatchMode="startsWith" id="id" filterBy="#{socio.id}"&gt;
              &lt;h:outputText value="#{socio.id}" /&gt;
          &lt;/p:column&gt;
          &lt;p:column headerText="Nome" filterBy="#{socio.nome}" filterMatchMode="startsWith" id="colunaNome" &gt;
              &lt;h:outputText value="#{socio.nome}"/&gt;
          &lt;/p:column&gt;
          &lt;p:column headerText="Sexo" style="width: 4%"&gt;
              &lt;h:outputText value="#{socio.sexo}"/&gt;
          &lt;/p:column&gt;
          &lt;p:column headerText="Data de Nascimento"&gt;
              &lt;h:outputText value="#{socio.dataNascimento}"&gt;
                  &lt;f:convertDateTime pattern="dd/MM/yyyy" /&gt;
              &lt;/h:outputText&gt;
          &lt;/p:column&gt;
          &lt;p:column headerText="Cargo"&gt;
              &lt;h:outputText value="#{socio.cargo}"/&gt;
          &lt;/p:column&gt;
  
  
          &lt;p:column headerText="Status"&gt;
              &lt;p:selectBooleanButton value="#{socio.ativo}" offLabel="Inativo" onLabel="Ativo" disabled="true"/&gt;
          &lt;/p:column&gt;
          &lt;p:column headerText="Editar"&gt;
              &lt;p:commandButton icon="ui-icon-search" oncomplete="editar.show();"&gt;
                  &lt;f:setPropertyActionListener target="#{sociosBean.socioEditar}" value="#{socio}"/&gt;
              &lt;/p:commandButton&gt;
          &lt;/p:column&gt;
          &lt;p:rowExpansion&gt;
  
              &lt;p:panelGrid id ="informacao" columns="2" style="width:400px; alignment-baseline: middle" &gt;
                  &lt;f:facet name="header"&gt;
                      #{socio.nome}
                  &lt;/f:facet&gt;
  
                  &lt;h:outputText value="ID"/&gt;
                  &lt;h:outputText value ="#{socio.id}"/&gt;
  
                  &lt;h:outputText value="Data de Nascimento"/&gt;
                  &lt;h:outputText value="#{socio.dataNascimento}"&gt;
                      &lt;f:convertDateTime pattern="dd/MM/yyyy" /&gt;
                  &lt;/h:outputText&gt;
  
                  &lt;h:outputText value="Nome do Pai"/&gt;
                  &lt;h:outputText value ="#{socio.nomePai}"/&gt;
  
                  &lt;h:outputText value="Nome da Mãe"/&gt;
                  &lt;h:outputText value ="#{socio.nomeMae}"/&gt;
  
                  &lt;h:outputText value="Cargo"/&gt;
                  &lt;h:outputText value ="#{socio.cargo}"/&gt;
  
                  &lt;h:outputText value="Telefone"/&gt;
                  &lt;h:outputText value ="#{socio.telefone}"/&gt;
  
                  &lt;h:outputText value="Ano de Admissão"/&gt;
                  &lt;h:outputText value ="#{socio.anoAdmissao}"/&gt;
  
                  &lt;h:outputText value ="Endereço"/&gt;
                  &lt;h:outputText value ="#{socio.endereco}"/&gt;
  
  
              &lt;/p:panelGrid&gt;
          &lt;/p:rowExpansion&gt;
      &lt;/p:dataTable&gt;
  
      &lt;p:button href="AID.xhtml" value="Voltar"/&gt;
      &lt;p:confirmDialog id="excluirSocio" message="Excluir sócio?"  
                       header="Aviso" severity="alert" widgetVar="excluir"&gt;  
  
          &lt;p:commandButton id="confirm" value="Sim" update="mensagem, socios" oncomplete="excluir.hide();"  
                           actionListener="#{sociosBean.excluirSocio()}"  icon="ui-icon-check"/&gt;  
          &lt;p:commandButton id="decline" value="Não" onclick="excluir.hide();" type="button" icon="ui-icon-close" /&gt;   
  
      &lt;/p:confirmDialog&gt;  
      &lt;p:dialog id="editarSocio" widgetVar="editar"&gt;
          &lt;p:panelGrid id="cadastro" columns="2"&gt;
              &lt;f:facet name="header"&gt;Editar Sócio&lt;/f:facet&gt;
  
              &lt;p:outputLabel for="nome" value="Nome:"/&gt;
              &lt;p:inputText id="nome" required ="true" value ="#{sociosBean.socioEditar.nome}"/&gt;
  
              &lt;p:outputLabel for="s" value="Sexo:"/&gt;
              &lt;p:selectOneRadio id="s" value="#{sociosBean.socioEditar.sexo}"&gt;
                  &lt;f:selectItem itemValue="m" itemLabel="Masculino"/&gt;
                  &lt;f:selectItem itemValue="f" itemLabel="Feminino"/&gt;
              &lt;/p:selectOneRadio&gt;
              &lt;p:outputLabel for ="serie" value="Série:"/&gt;
              &lt;p:selectOneMenu id="serie" value="#{sociosBean.socioEditar.serie}"&gt;
                  &lt;f:selectItem itemLabel="3º Ensino Médio" itemValue="3EM" /&gt; 
                  &lt;f:selectItem itemLabel="2º Ensino Médio" itemValue="2EM" /&gt;
                  &lt;f:selectItem itemLabel="1º Ensino Médio" itemValue="1EM" /&gt;
                  &lt;f:selectItem itemLabel="8º Ensino Fundamental" itemValue="8EF" /&gt;
                  &lt;f:selectItem itemLabel="7º Ensino Fundamental" itemValue="7EF" /&gt; 
                  &lt;f:selectItem itemLabel="6º Ensino Fundamental" itemValue="6EF" /&gt; 
                  &lt;f:selectItem itemLabel="5º Ensino Fundamental" itemValue="5EF" /&gt; 
  
              &lt;/p:selectOneMenu&gt;
              &lt;p:outputLabel for ="endereco" value ="Endereço:"/&gt;
              &lt;p:inputText id ="endereco" maxlength="60" value="#{sociosBean.socioEscolhido.endereco}"/&gt;
  
              &lt;p:outputLabel for ="telefone" value ="Telefone:"/&gt;
              &lt;p:inputMask id="telefone"  value="#{sociosBean.socioEscolhido.telefone}" mask="(99)9999-9999"/&gt;
              &lt;p:outputLabel for ="nomePai" value ="Nome do Pai:"/&gt;
              &lt;p:inputText id ="nomePai" maxlength="45" value="#{sociosBean.socioEscolhido.nomePai}"/&gt;
  
              &lt;p:outputLabel for ="nomeMae" value ="Nome da Mãe:"/&gt;
              &lt;p:inputText id ="nomeMae" maxlength="45" value="#{sociosBean.socioEscolhido.nomeMae}"/&gt;
  
              &lt;p:outputLabel for ="dataNascimento" value ="Data de nascimento: "/&gt;
              &lt;p:calendar id="dataNascimento" value="#{sociosBean.socioEscolhido.dataNascimento}" required="true" navigator ="true" locale ="pt" pattern="dd/MM/yyyy"/&gt;
  
              &lt;p:outputLabel for ="cargo" value ="Cargo:"/&gt;
              &lt;p:inputText id ="cargo" maxlength="25" value="#{sociosBean.socioEscolhido.cargo}"/&gt;
              &lt;p:outputLabel for ="anoAdmissao" value ="Ano Admissão:"/&gt;
              &lt;p:inputMask id ="anoAdmissao" maxlength="4" mask="9999" value="#{sociosBean.socioEscolhido.anoAdmissao}"/&gt;
  
              &lt;f:facet name="footer"&gt;
                  &lt;p:commandButton id="btnEditar" value="Editar" actionListener="#{sociosBean.editarSocio()}"/&gt;
  
              &lt;/f:facet&gt;
          &lt;/p:panelGrid&gt;
      &lt;/p:dialog&gt;
  
  &lt;/h:form&gt;
  </code></pre>
  
  <p></p>
  
  <p>Bean:</p>
  
  <pre><code>    package com.beans;
  
  import com.dao.SociosDAO;
  import java.util.ArrayList;
  import model.hibernate.Socios;
  import java.util.Date;
  import java.util.List;
  import javax.faces.application.FacesMessage;
  import javax.faces.bean.ManagedBean;
  import javax.faces.bean.SessionScoped;
  import javax.faces.context.FacesContext;
  
  @ManagedBean
  @SessionScoped
  /**
   *
   * @author João Pedro Sacheti
   */
  public class SociosBean {
  
      private String nome;
      private String serie;
      private char sexo;
      private String endereco;
      private String nomePai;
      private String nomeMae;
      private Date dataNascimento;
      private String cargo;
      private Integer anoAdmissao;
      private boolean ativo;
      private String telefone;
      private List&lt;Socios&gt; socioFiltro;
      private ArrayList&lt;Socios&gt; socios;
      private Socios socioEscolhido;
      private Socios socioEditar;
      //getters and setters
  
  public SociosBean() {
      this.socios = new ArrayList&lt;Socios&gt;();
      this.socioEditar = new Socios();
  }
  </code></pre>