• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Primefaces: How to insert an object attributes on a PanelGrid?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone, I'm working in a project for my local school club to create a database and save the information of the members. I'm using PrimeFaces and Hibernate for doing so, but I'm having trouble in DataTables. I have a DataTable that shows some infomation about members, and since all the data don't fit in the datable, I made a button to pop a dialog with all the other info. Point is, the button only open a dialog with information of the first member. I'm also making a rowToggler to allow the admin to edit the info, and the selection property is very useful, but don't put the data in the fields of the form. Any ideas of how I could solve this problem? Thank you very much.

ManagedBean:

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 Joao 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;




public List<Socios> getSocioFiltro() {
return socioFiltro;
}

public void setSocioFiltro(List<Socios> socioFiltro) {
this.socioFiltro = socioFiltro;
}

public boolean isAtivo() {
return ativo;
}

public void setAtivo(boolean ativo) {
this.ativo = ativo;
}

public Socios getSocioEscolhido() {
return socioEscolhido;
}

public void setSocioEscolhido(Socios socioEscolhido) {
this.socioEscolhido = socioEscolhido;
}

public ArrayList<Socios> getSocios() {

SociosDAO sd = new SociosDAO();
socios = (ArrayList<Socios>) sd.listarSociosAtivos();
return socios;
}

public void setSocios(ArrayList<Socios> socios) {
this.socios = socios;
}

public Integer getAnoAdmissao() {
return anoAdmissao;
}

public void setAnoAdmissao(Integer anoAdmissao) {
this.anoAdmissao = anoAdmissao;
}

public String getCargo() {
return cargo;
}

public void setCargo(String cargo) {
this.cargo = cargo;
}

public Date getDataNascimento() {
return dataNascimento;
}

public void setDataNascimento(Date dataNascimento) {
this.dataNascimento = dataNascimento;
}

public String getEndereco() {
return endereco;
}

public void setEndereco(String endereco) {
this.endereco = endereco;
}

public String getNome() {
return nome;
}

public void setNome(String nome) {
this.nome = nome;
}

public String getNomeMae() {
return nomeMae;
}

public void setNomeMae(String nomeMae) {
this.nomeMae = nomeMae;
}

public String getNomePai() {
return nomePai;
}

public void setNomePai(String nomePai) {
this.nomePai = nomePai;
}

public String getSerie() {
return serie;
}

public void setSerie(String serie) {
this.serie = serie;
}

public char getSexo() {
return sexo;
}

public void setSexo(char sexo) {
this.sexo = sexo;
}

public String getTelefone() {
return telefone;
}

public void setTelefone(String telefone) {
this.telefone = telefone;
}

public SociosBean() {
this.socios = new ArrayList<Socios>();
}

public void salvar() { //saves the member in DB
try {
SociosDAO sd = new SociosDAO();
Socios s = new Socios();
s.setNome(getNome());
s.setDataNascimento(getDataNascimento());
s.setEndereco(getEndereco());
s.setNomePai(getNomePai());
s.setNomeMae(getNomeMae());
s.setCargo(getCargo());
s.setSexo(getSexo());
s.setSerie(getSerie());
s.setAtivo(isAtivo());
s.setAnoAdmissao(getAnoAdmissao());
s.setTelefone(getTelefone());
sd.salvar(s);
System.out.println("Salvou");
FacesMessage mensagem = new FacesMessage(FacesMessage.SEVERITY_INFO, "Feito", "Sócio " + getNome() + " Salvo");

FacesContext.getCurrentInstance().addMessage(null, mensagem);
} catch (Exception e) {
System.err.println("Erro ao salvar " + e);

}
}

public void excluirSocio() { //deletes the member

System.out.println(socioEscolhido.getNome());
socios.remove(socioEscolhido);
System.out.println("Sócio: " + socioEscolhido.getNome() + " excluido");
SociosDAO sd = new SociosDAO();
sd.excluir(socioEscolhido);

socioEscolhido = null;
socios = (ArrayList<Socios>) sd.listarSociosAtivos();
for (Socios Socio : socios) {
System.out.println(Socio.getNome());
}


FacesMessage mensagem = new FacesMessage(FacesMessage.SEVERITY_INFO, "Feito", "Sócio excluido");

FacesContext.getCurrentInstance().addMessage(null, mensagem);
}

public void editarSocio() { //edition
SociosDAO sd = new SociosDAO();
System.out.println(socioEscolhido.getNome());
sd.editar(socioEscolhido);
FacesMessage mensagem = new FacesMessage(FacesMessage.SEVERITY_INFO, "Feito", "Sócio alterado");
FacesContext.getCurrentInstance().addMessage(null, mensagem);
}
}

[/code]

XHTML WebPage:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xml:p= "http://primefaces.org/ui"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Lista de Sócios</title>
</h:head>
<h:body>

<h:form>
<p:growl id="mensagem" />
<p:contextMenu for="socios" >
<p:menuitem value="Editar" update="socios" icon="ui-icon-pencil" onclick="editar.show();">
</p:menuitem>
<p:menuitem value="Excluir" update="socios" icon="ui-icon-close" onclick="excluir.show();"/>
</p:contextMenu>
<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">

<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="Reuniões Participadas">
<h:outputText value="#{socio.reunioesParticipadas}"/>
</p:column>
<p:column headerText="Faltas">
<h:outputText value="#{socio.faltas}"/>
</p:column>
<p:column headerText="Reposições">
<h:outputText value="#{socio.reposicoes}"/>
</p:column>
<p:column headerText="Status">
<p:selectBooleanButton value="#{socio.ativo}" offLabel="Inativo" onLabel="Ativo" disabled="true"/>
</p:column>
<p:column headerText="Info">
<p:commandButton type="button" icon="ui-icon-search" onclick="info.show();"/>
</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}"/>

<p:outputLabel for="nome" value="Nome"/>
<p:inputText id="nome" maxlength="45" required="true" value="#{socio.nome}"/>

<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="Porcentagem de frequência"/>
<h:outputText value ="#{socio.porcentagemFrequencia}"/>

<h:outputText value="Reposições"/>
<h:outputText value ="#{socio.reposicoes}"/>

<h:outputText value="Faltas"/>
<h:outputText value ="#{socio.faltas}"/>

<h:outputText value="Total de Reuniões"/>
<h:outputText value ="#{socio.reunioesParticipadas}"/>


</p:panelGrid>
</p:rowExpansion>
</p:dataTable>


<p:dialog id="edita" widgetVar="editar">
~~
</p:dialog>
<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" maxlength="45" required="true" value="#{socioBean.socioEscolhido.nome}">
</p:inputText>
<p:outputLabel for="s" value="Sexo:"/>
<p:selectOneRadio id="s" value="#{sociosBean.socioEscolhido.sexo}" required="true">
<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" required="true" value="#{sociosBean.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" required="true" maxlength="60" value="#{sociosBean.endereco}"/>

<p:outputLabel for ="telefone" value ="Telefone:"/>
<p:inputMask id="telefone" required="true" value="#{sociosBean.telefone}" mask="(99)9999-9999"/>
<p:outputLabel for ="nomePai" value ="Nome do Pai:"/>
<p:inputText id ="nomePai" required="true" maxlength="45" value="#{sociosBean.nomePai}"/>

<p:outputLabel for ="nomeMae" value ="Nome da Mãe:"/>
<p:inputText id ="nomeMae" required="true" maxlength="45" value="#{sociosBean.nomeMae}"/>

<p:outputLabel for ="dataNascimento" value ="Data de nascimento: "/>
<p:calendar id="dataNascimento" value="#{sociosBean.dataNascimento}" required="true" navigator ="true" locale ="pt" pattern="dd/MM/yyyy"/>

<p:outputLabel for ="cargo" value ="Cargo:"/>
<p:inputText id ="cargo" required="true" maxlength="25" value="#{sociosBean.cargo}"/>
<p:outputLabel for ="anoAdmissao" value ="Ano Admissão:"/>
<p:inputMask id ="anoAdmissao" required="true" maxlength="4" mask="9999" value="#{sociosBean.anoAdmissao}"/>
<p:outputLabel for ="ativo" value="Status"/>
<p:selectBooleanButton id="ativo" value ="#{sociosBean.ativo}" required="true" offLabel="Inativo" onLabel="Ativo" onIcon="ui-icon-check" offIcon="ui-icon-cancel"/>
<f:facet name="footer">
<p:commandButton id="btnEditar" value="Editar" actionListener="#{sociosBean.editarSocio()}"/>

</f:facet>
</p:panelGrid>
</p:dialog>
<p:dialog widgetVar="info" maximizable="true" id="infos" closeOnEscape="true" closable="true">
<p:panelGrid id ="display" 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="Porcentagem de frequência"/>
<h:outputText value ="#{socio.porcentagemFrequencia}"/>

<h:outputText value="Reposições"/>
<h:outputText value ="#{socio.reposicoes}"/>

<h:outputText value="Faltas"/>
<h:outputText value ="#{socio.faltas}"/>

<h:outputText value="Total de Reuniões"/>
<h:outputText value ="#{socio.reunioesParticipadas}"/>


</p:panelGrid>
</p:dialog>
</h:form>
</h:body>
</html>







 
Time flies like an arrow. Fruit flies like a banana. Steve flies like a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic