所以,我的页面上有一个dataTable,它显示了一些基本信息和行扩展,以显示额外的信息。我正在尝试创建一个按钮/上下文菜单来显示一个对话框,以便用户可以编辑表格上的信息(基本和额外的,所有形式),但我从表中获取这些数据时遇到了麻烦。当我单击按钮显示对话框时,它只显示第一行的信息,而不是我选择的行。有任何想法吗?谢谢。代码如下。
<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">
<p:menuitem value ="Editar" update="socios" icon ="ui-icon-search"
oncomplete="editar.show();">
<f:setPropertyActionListener target="#{sociosBean.socioEditar}" value="#{socio}"/>
</p:menuitem>
<p:menuitem value="Excluir" update="socios" icon="ui-icon-close" onclick="excluir.show();"/>
<f:facet name="header">
<p:outputPanel>
<h:outputText value="Socios" />
</p:outputPanel>
</f:facet>
<p:column style="width:2%">
<p:rowToggler />
</p:column>
<p:column headerText="ID" filterMatchMode="startsWith" id="id" filterBy="#{socio.id}">
<h:outputText value="#{socio.id}" />
</p:column>
<p:column headerText="Nome" filterBy="#{socio.nome}" filterMatchMode="startsWith" id="colunaNome" >
<h:outputText value="#{socio.nome}"/>
</p:column>
<p:column headerText="Sexo" style="width: 4%">
<h:outputText value="#{socio.sexo}"/>
</p:column>
<p:column headerText="Data de Nascimento">
<h:outputText value="#{socio.dataNascimento}">
<f:convertDateTime pattern="dd/MM/yyyy" />
</h:outputText>
</p:column>
<p:column headerText="Cargo">
<h:outputText value="#{socio.cargo}"/>
</p:column>
<p:column headerText="Status">
<p:selectBooleanButton value="#{socio.ativo}" offLabel="Inativo" onLabel="Ativo" disabled="true"/>
</p:column>
<p:column headerText="Editar">
<p:commandButton icon="ui-icon-search" oncomplete="editar.show();">
<f:setPropertyActionListener target="#{sociosBean.socioEditar}" value="#{socio}"/>
</p:commandButton>
</p:column>
<p:rowExpansion>
<p:panelGrid id ="informacao" columns="2" style="width:400px; alignment-baseline: middle" >
<f:facet name="header">
#{socio.nome}
</f:facet>
<h:outputText value="ID"/>
<h:outputText value ="#{socio.id}"/>
<h:outputText value="Data de Nascimento"/>
<h:outputText value="#{socio.dataNascimento}">
<f:convertDateTime pattern="dd/MM/yyyy" />
</h:outputText>
<h:outputText value="Nome do Pai"/>
<h:outputText value ="#{socio.nomePai}"/>
<h:outputText value="Nome da Mãe"/>
<h:outputText value ="#{socio.nomeMae}"/>
<h:outputText value="Cargo"/>
<h:outputText value ="#{socio.cargo}"/>
<h:outputText value="Telefone"/>
<h:outputText value ="#{socio.telefone}"/>
<h:outputText value="Ano de Admissão"/>
<h:outputText value ="#{socio.anoAdmissao}"/>
<h:outputText value ="Endereço"/>
<h:outputText value ="#{socio.endereco}"/>
</p:panelGrid>
</p:rowExpansion>
</p:dataTable>
<p:button href="AID.xhtml" value="Voltar"/>
<p:confirmDialog id="excluirSocio" message="Excluir sócio?"
header="Aviso" severity="alert" widgetVar="excluir">
<p:commandButton id="confirm" value="Sim" update="mensagem, socios" oncomplete="excluir.hide();"
actionListener="#{sociosBean.excluirSocio()}" icon="ui-icon-check"/>
<p:commandButton id="decline" value="Não" onclick="excluir.hide();" type="button" icon="ui-icon-close" />
</p:confirmDialog>
<p:dialog id="editarSocio" widgetVar="editar">
<p:panelGrid id="cadastro" columns="2">
<f:facet name="header">Editar Sócio</f:facet>
<p:outputLabel for="nome" value="Nome:"/>
<p:inputText id="nome" required ="true" value ="#{sociosBean.socioEditar.nome}"/>
<p:outputLabel for="s" value="Sexo:"/>
<p:selectOneRadio id="s" value="#{sociosBean.socioEditar.sexo}">
<f:selectItem itemValue="m" itemLabel="Masculino"/>
<f:selectItem itemValue="f" itemLabel="Feminino"/>
</p:selectOneRadio>
<p:outputLabel for ="serie" value="Série:"/>
<p:selectOneMenu id="serie" value="#{sociosBean.socioEditar.serie}">
<f:selectItem itemLabel="3º Ensino Médio" itemValue="3EM" />
<f:selectItem itemLabel="2º Ensino Médio" itemValue="2EM" />
<f:selectItem itemLabel="1º Ensino Médio" itemValue="1EM" />
<f:selectItem itemLabel="8º Ensino Fundamental" itemValue="8EF" />
<f:selectItem itemLabel="7º Ensino Fundamental" itemValue="7EF" />
<f:selectItem itemLabel="6º Ensino Fundamental" itemValue="6EF" />
<f:selectItem itemLabel="5º Ensino Fundamental" itemValue="5EF" />
</p:selectOneMenu>
<p:outputLabel for ="endereco" value ="Endereço:"/>
<p:inputText id ="endereco" maxlength="60" value="#{sociosBean.socioEscolhido.endereco}"/>
<p:outputLabel for ="telefone" value ="Telefone:"/>
<p:inputMask id="telefone" value="#{sociosBean.socioEscolhido.telefone}" mask="(99)9999-9999"/>
<p:outputLabel for ="nomePai" value ="Nome do Pai:"/>
<p:inputText id ="nomePai" maxlength="45" value="#{sociosBean.socioEscolhido.nomePai}"/>
<p:outputLabel for ="nomeMae" value ="Nome da Mãe:"/>
<p:inputText id ="nomeMae" maxlength="45" value="#{sociosBean.socioEscolhido.nomeMae}"/>
<p:outputLabel for ="dataNascimento" value ="Data de nascimento: "/>
<p:calendar id="dataNascimento" value="#{sociosBean.socioEscolhido.dataNascimento}" required="true" navigator ="true" locale ="pt" pattern="dd/MM/yyyy"/>
<p:outputLabel for ="cargo" value ="Cargo:"/>
<p:inputText id ="cargo" maxlength="25" value="#{sociosBean.socioEscolhido.cargo}"/>
<p:outputLabel for ="anoAdmissao" value ="Ano Admissão:"/>
<p:inputMask id ="anoAdmissao" maxlength="4" mask="9999" value="#{sociosBean.socioEscolhido.anoAdmissao}"/>
<f:facet name="footer">
<p:commandButton id="btnEditar" value="Editar" actionListener="#{sociosBean.editarSocio()}"/>
</f:facet>
</p:panelGrid>
</p:dialog>
</h:form>
豆:
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<Socios> socioFiltro;
private ArrayList<Socios> socios;
private Socios socioEscolhido;
private Socios socioEditar;
//getters and setters
public SociosBean() {
this.socios = new ArrayList<Socios>();
this.socioEditar = new Socios();
}
答案 0 :(得分:0)
我猜测问题是你在显示时没有更新对话框的内容。因此,您必须将update="editarSocio:cadastro"
添加到用于显示对话框的commandButton中。
但请注意,您必须输入的ID取决于XHTML的结构,我不知道。