Fórum Exibir uma lista Many-to-many no Datatable JSF #417608
29/05/2012
0
Sou novo por aqui e iniciante em java, estou desenvolvendo uma pequena aplicação em Java utilizando Jfs,hibernate,MySql até ai tudo bem. Realizei os mapeamentos das classes de entidades algumas consulta já consigo receber os dados o problema esta numa propriedade Many-to-many que é composta por 3 tabelas ALUNOS, TIPO_DOCUMENTOS e a tabela de Relacionamento ALUNOS_DOCUMENTOS.Bem montei um para exibir os dados de cadas aluno utilizando uns tabs adicionei uma tab onde quero exibir os documentos que o aluno entregou no momento da matrícula então coloquei um datatable para que este possa listar esta documentos entregues o problema é que o objeto é perssistido mas com null e não exibe nada na tela . Já pesquisei na net existem alguns relatos mas o pessoal não exibe uma solução concreta que possa me ajudar. Segue abaixo o código de minha classes :
Classe Aluno:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.dominio.Aluno;
import com.dominio.Estado_Civil.Estado_Civil;
import com.dominio.Turmas.*;
import com.dominio.Tipo_Documento.*;
import com.dominio.Tipo_Status.*;
import com.dominio.cursos.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.Date;
import javax.faces.model.SelectItem;
import javax.persistence.*;
/**
*
* @author Gustavo
*/
@Entity
@Table(name=alunos)
public class Aluno implements Serializable {
private Long cd_aluno;
private String matricula_ant;
private String creci;
private Tipo_Status cd_status;
private Date data_cadastro;
private String nome;
private String foto;
private Date dt_nascimento;
private String endereco;
private String bairro;
private String complemento;
private String cidade;
private String estado;
private String cep;
private String endereco_ativo;
private String telefone1;
private String telefone2;
private String telefone3;
private String cnpj_cpf;
private String rg;
private String rg_orgao;
private String site;
private String email;
private String cob_endereco;
private String cob_bairro;
private String cob_complemento;
private String cob_cidade;
private String cob_estado;
private String cob_cep;
private String endereco_cob_ativo;
private String insc_estadual;
private String insc_municipal;
private String filiacao_pai;
private String filiacao_mae;
private String observacao;
private Date dt_desistencia;
private Date dt_trancamento;
private Date dt_conclusao_curso;
private String naturalidade;
private String nacionalidade;
private Estado_Civil estado_civil;
private Cursos curso ;
private String profissao;
private List<SelectItem> documentos ;
private Set<Turmas> turma = new HashSet<Turmas>(0);
/**
* @return the cd_aluno
*/
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = cd_aluno)
public Long getCd_aluno() {
return cd_aluno;
}
/**
* @param cd_aluno the cd_aluno to set
*/
public void setCd_aluno(Long cd_aluno) {
this.cd_aluno = cd_aluno;
}
/**
* @return the matricula_ant
*/
@Column(name=matricula_ant)
public String getMatricula_ant() {
return matricula_ant;
}
/**
* @param matricula_ant the matricula_ant to set
*/
public void setMatricula_ant(String matricula_ant) {
this.matricula_ant = matricula_ant;
}
/**
* @return the creci
*/
@Column(name=creci)
public String getCreci() {
return creci;
}
/**
* @param creci the creci to set
*/
public void setCreci(String creci) {
this.creci = creci;
}
/**
* @return the cd_status
*/
@ManyToOne(cascade = CascadeType.ALL)
public Tipo_Status getCd_status() {
return cd_status;
}
/**
* @param cd_status the cd_status to set
*/
public void setCd_status(Tipo_Status cd_status) {
this.cd_status = cd_status;
}
/**
* @return the data_cadastro
*/
@Column(name=data_cadastro)
@Temporal(TemporalType.DATE)
public Date getData_cadastro() {
return data_cadastro;
}
/**
* @param data_cadastro the data_cadastro to set
*/
public void setData_cadastro(Date data_cadastro) {
this.data_cadastro = data_cadastro;
}
/**
* @return the nome
*/
@Column(name=nome)
public String getNome() {
return nome;
}
/**
* @param nome the nome to set
*/
public void setNome(String nome) {
this.nome = nome;
}
/**
* @return the foto
*/
@Column(name=foto)
public String getFoto() {
return foto;
}
/**
* @param foto the foto to set
*/
public void setFoto(String foto) {
this.foto = foto;
}
/**
* @return the dt_nascimento
*/
@Column(name=dt_nascimento)
@Temporal(TemporalType.DATE)
public Date getDt_nascimento() {
return dt_nascimento;
}
/**
* @param dt_nascimento the dt_nascimento to set
*/
public void setDt_nascimento(Date dt_nascimento) {
this.dt_nascimento = dt_nascimento;
}
/**
* @return the endereco
*/
@Column(name=endereco)
public String getEndereco() {
return endereco;
}
/**
* @param endereco the endereco to set
*/
public void setEndereco(String endereco) {
this.endereco = endereco;
}
/**
* @return the bairro
*/
@Column(name=bairro)
public String getBairro() {
return bairro;
}
/**
* @param bairro the bairro to set
*/
public void setBairro(String bairro) {
this.bairro = bairro;
}
/**
* @return the complemento
*/
@Column(name=complemento)
public String getComplemento() {
return complemento;
}
/**
* @param complemento the complemento to set
*/
public void setComplemento(String complemento) {
this.complemento = complemento;
}
/**
* @return the cidade
*/
@Column(name=cidade)
public String getCidade() {
return cidade;
}
/**
* @param cidade the cidade to set
*/
public void setCidade(String cidade) {
this.cidade = cidade;
}
/**
* @return the estado
*/
@Column(name=estado)
public String getEstado() {
return estado;
}
/**
* @param estado the estado to set
*/
public void setEstado(String estado) {
this.estado = estado;
}
/**
* @return the cep
*/
@Column(name=cep)
public String getCep() {
return cep;
}
/**
* @param cep the cep to set
*/
public void setCep(String cep) {
this.cep = cep;
}
/**
* @return the endereco_ativo
*/
@Column(name=endereco_ativo)
public String getEndereco_ativo() {
return endereco_ativo;
}
/**
* @param endereco_ativo the endereco_ativo to set
*/
public void setEndereco_ativo(String endereco_ativo) {
this.endereco_ativo = endereco_ativo;
}
/**
* @return the telefone1
*/
@Column(name=telefone1)
public String getTelefone1() {
return telefone1;
}
/**
* @param telefone1 the telefone1 to set
*/
public void setTelefone1(String telefone1) {
this.telefone1 = telefone1;
}
/**
* @return the telefone2
*/
@Column(name=telefone2)
public String getTelefone2() {
return telefone2;
}
/**
* @param telefone2 the telefone2 to set
*/
public void setTelefone2(String telefone2) {
this.telefone2 = telefone2;
}
/**
* @return the telefone3
*/
@Column(name=telefone3)
public String getTelefone3() {
return telefone3;
}
/**
* @param telefone3 the telefone3 to set
*/
public void setTelefone3(String telefone3) {
this.telefone3 = telefone3;
}
/**
* @return the cnpj_cpf
*/
@Column(name=cnpj_cpf)
public String getCnpj_cpf() {
return cnpj_cpf;
}
/**
* @param cnpj_cpf the cnpj_cpf to set
*/
public void setCnpj_cpf(String cnpj_cpf) {
this.cnpj_cpf = cnpj_cpf;
}
/**
* @return the rg
*/
@Column(name=rg)
public String getRg() {
return rg;
}
/**
* @param rg the rg to set
*/
public void setRg(String rg) {
this.rg = rg;
}
/**
* @return the rg_orgao
*/
@Column(name=rg_orgao)
public String getRg_orgao() {
return rg_orgao;
}
/**
* @param rg_orgao the rg_orgao to set
*/
public void setRg_orgao(String rg_orgao) {
this.rg_orgao = rg_orgao;
}
/**
* @return the site
*/
@Column(name=site)
public String getSite() {
return site;
}
/**
* @param site the site to set
*/
public void setSite(String site) {
this.site = site;
}
/**
* @return the email
*/
@Column(name=email)
public String getEmail() {
return email;
}
/**
* @param email the email to set
*/
public void setEmail(String email) {
this.email = email;
}
/**
* @return the cob_endereco
*/
@Column(name=cob_endereco)
public String getCob_endereco() {
return cob_endereco;
}
/**
* @param cob_endereco the cob_endereco to set
*/
public void setCob_endereco(String cob_endereco) {
this.cob_endereco = cob_endereco;
}
/**
* @return the cob_bairro
*/
@Column(name=cob_bairro)
public String getCob_bairro() {
return cob_bairro;
}
/**
* @param cob_bairro the cob_bairro to set
*/
public void setCob_bairro(String cob_bairro) {
this.cob_bairro = cob_bairro;
}
/**
* @return the cob_complemento
*/
@Column(name=cob_complemento)
public String getCob_complemento() {
return cob_complemento;
}
/**
* @param cob_complemento the cob_complemento to set
*/
public void setCob_complemento(String cob_complemento) {
this.cob_complemento = cob_complemento;
}
/**
* @return the cob_cidade
*/
@Column(name=cob_cidade)
public String getCob_cidade() {
return cob_cidade;
}
/**
* @param cob_cidade the cob_cidade to set
*/
public void setCob_cidade(String cob_cidade) {
this.cob_cidade = cob_cidade;
}
/**
* @return the cob_estado
*/
@Column(name=cob_estado)
public String getCob_estado() {
return cob_estado;
}
/**
* @param cob_estado the cob_estado to set
*/
public void setCob_estado(String cob_estado) {
this.cob_estado = cob_estado;
}
/**
* @return the cob_cep
*/
@Column(name=cob_cep)
public String getCob_cep() {
return cob_cep;
}
/**
* @param cob_cep the cob_cep to set
*/
public void setCob_cep(String cob_cep) {
this.cob_cep = cob_cep;
}
/**
* @return the endereco_cob_ativo
*/
@Column(name=endereco_cob_ativo)
public String getEndereco_cob_ativo() {
return endereco_cob_ativo;
}
/**
* @param endereco_cob_ativo the endereco_cob_ativo to set
*/
public void setEndereco_cob_ativo(String endereco_cob_ativo) {
this.endereco_cob_ativo = endereco_cob_ativo;
}
/**
* @return the insc_estadual
*/
@Column(name=insc_estadual)
public String getInsc_estadual() {
return insc_estadual;
}
/**
* @param insc_estadual the insc_estadual to set
*/
public void setInsc_estadual(String insc_estadual) {
this.insc_estadual = insc_estadual;
}
/**
* @return the insc_municipal
*/
@Column(name=insc_municipal)
public String getInsc_municipal() {
return insc_municipal;
}
/**
* @param insc_municipal the insc_municipal to set
*/
public void setInsc_municipal(String insc_municipal) {
this.insc_municipal = insc_municipal;
}
/**
* @return the filiacao_pai
*/
@Column(name=filiacao_pai)
public String getFiliacao_pai() {
return filiacao_pai;
}
/**
* @param filiacao_pai the filiacao_pai to set
*/
public void setFiliacao_pai(String filiacao_pai) {
this.filiacao_pai = filiacao_pai;
}
/**
* @return the filiacao_mae
*/
@Column(name=filiacao_mae)
public String getFiliacao_mae() {
return filiacao_mae;
}
/**
* @param filiacao_mae the filiacao_mae to set
*/
public void setFiliacao_mae(String filiacao_mae) {
this.filiacao_mae = filiacao_mae;
}
/**
* @return the observacao
*/
@Column(name=observacao)
public String getObservacao() {
return observacao;
}
/**
* @param observacao the observacao to set
*/
public void setObservacao(String observacao) {
this.observacao = observacao;
}
/**
* @return the dt_desistencia
*/
@Column(name=dt_desistencia)
@Temporal(TemporalType.DATE)
public Date getDt_desistencia() {
return dt_desistencia;
}
/**
* @param dt_desistencia the dt_desistencia to set
*/
public void setDt_desistencia(Date dt_desistencia) {
this.dt_desistencia = dt_desistencia;
}
/**
* @return the dt_trancamento
*/
@Column(name=dt_trancamento)
@Temporal(TemporalType.DATE)
public Date getDt_trancamento() {
return dt_trancamento;
}
/**
* @param dt_trancamento the dt_trancamento to set
*/
public void setDt_trancamento(Date dt_trancamento) {
this.dt_trancamento = dt_trancamento;
}
/**
* @return the dt_conclusao_curso
*/
@Column(name=dt_conclusao_curso)
@Temporal(TemporalType.DATE)
public Date getDt_conclusao_curso() {
return dt_conclusao_curso;
}
/**
* @param dt_conclusao_curso the dt_conclusao_curso to set
*/
public void setDt_conclusao_curso(Date dt_conclusao_curso) {
this.dt_conclusao_curso = dt_conclusao_curso;
}
/**
* @return the naturalidade
*/
@Column(name=naturalidade)
public String getNaturalidade() {
return naturalidade;
}
/**
* @param naturalidade the naturalidade to set
*/
public void setNaturalidade(String naturalidade) {
this.naturalidade = naturalidade;
}
/**
* @return the nacionalidade
*/
@Column(name=nacionalidade)
public String getNacionalidade() {
return nacionalidade;
}
/**
* @param nacionalidade the nacionalidade to set
*/
public void setNacionalidade(String nacionalidade) {
this.nacionalidade = nacionalidade;
}
@ManyToOne(cascade = CascadeType.ALL)
public Estado_Civil getEstado_civil() {
return estado_civil;
}
public void setEstado_civil(Estado_Civil estado_civil) {
this.estado_civil = estado_civil;
}
/**
* @return the profissao
*/
@Column(name=profissao)
public String getProfissao() {
return profissao;
}
/**
* @param profissao the profissao to set
*/
public void setProfissao(String profissao) {
this.profissao = profissao;
}
//
@ManyToMany(fetch=FetchType.EAGER )
@JoinTable(name = alunos_documentos, joinColumns = { @JoinColumn(name = cd_alunos_fk) })
public List<Tipo_Documento> getDocumentos() {
return this.documentos;
}
public void setDocumentos(List<Tipo_Documento> documentos) {
this.documentos = documentos;
}
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(name = turmas_alunos, joinColumns = { @JoinColumn(name = cd_aluno_fk) },
inverseJoinColumns = { @JoinColumn(name = cd_turma_fk) })
public Set<Turmas> getTurma() {
return turma;
}
public void setTurma(Set<Turmas> turma) {
this.turma = turma;
}
@ManyToOne(cascade = CascadeType.ALL)
public Cursos getCurso() {
return curso;
}
public void setCurso(Cursos curso) {
this.curso = curso;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Aluno other = (Aluno) obj;
if (this.cd_aluno != other.cd_aluno && (this.cd_aluno == null || !this.cd_aluno.equals(other.cd_aluno))) {
return false;
}
return true;
}
@Override
public int hashCode() {
int hash = 7;
hash = 13 * hash + (this.cd_aluno != null ? this.cd_aluno.hashCode() : 0);
return hash;
}
}
Classe Tipo_Documentos
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.dominio.Tipo_Documento;
import java.io.Serializable;
import javax.persistence.*;
/**
*
* @author Gustavo
*/
@Entity
@Table(name=tipo_documento)
public class Tipo_Documento implements Serializable {
private Long cd_documento;
private String nome;
private String tipo;
private String observacao;
/**
* @return the cd_documento
*/
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getCd_documento() {
return cd_documento;
}
/**
* @param cd_documento the cd_documento to set
*/
public void setCd_documento(Long cd_documento) {
this.cd_documento = cd_documento;
}
/**
* @return the nome
*/
@Column(name=nome)
public String getNome() {
return nome;
}
/**
* @param nome the nome to set
*/
public void setNome(String nome) {
this.nome = nome;
}
/**
* @return the tipo
*/
@Column(name=tipo)
public String getTipo() {
return tipo;
}
/**
* @param tipo the tipo to set
*/
public void setTipo(String tipo) {
this.tipo = tipo;
}
/**
* @return the observacao
*/
@Column(name=observacao)
public String getObservacao() {
return observacao;
}
/**
* @param observacao the observacao to set
*/
public void setObservacao(String observacao) {
this.observacao = observacao;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Tipo_Documento other = (Tipo_Documento) obj;
if (this.cd_documento != other.cd_documento && (this.cd_documento == null || !this.cd_documento.equals(other.cd_documento))) {
return false;
}
return true;
}
@Override
public int hashCode() {
int hash = 7;
hash = 47 * hash + (this.cd_documento != null ? this.cd_documento.hashCode() : 0);
return hash;
}
}
CadastroalunoBean.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.visao.Aluno;
/**
*
* @author Gustavo
*/
import com.dominio.Aluno.Aluno;
import com.dominio.Estado.Estado;
import com.dominio.Estado_Civil.Estado_Civil;
import com.dominio.Tipo_Documento.Tipo_Documento;
import com.dominio.Tipo_Status.*;
import com.negocio.Aluno.AlunoService;
import com.negocio.Estado_Civil.Estado_CivilService;
import com.negocio.Exception.RegraNegocioException;
import com.negocio.Tipo_Status.Tipo_StatusService;
import java.util.ArrayList;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;
/**
*
* @author Gustavo
*/
public class CadastroAlunoBean {
private Aluno alunoEdicao;
//private List<Tipo_Documento> Lsttipo_documento = new ArrayList<Tipo_Documento>();
private List<SelectItem> estados_civil;
private List<SelectItem> status_aluno;
private List<SelectItem> estado;
private List<Tipo_Documento> documentos;
public List<Tipo_Documento> getDocumentos() {
return documentos;
}
public void setDocumentos(List<Tipo_Documento> documentos) {
this.documentos = documentos;
}
public String inicializar() {
this.alunoEdicao = new Aluno();
this.estados_civil = null;
this.status_aluno = null;
this.estado = null;
// this.tipo_documento = null ;
return cadastroAluno;
}
public void salvar(ActionEvent event) {
FacesContext context = FacesContext.getCurrentInstance();
try {
new AlunoService().salvar(this.alunoEdicao);
this.alunoEdicao = new Aluno() ;
FacesMessage msg = new FacesMessage(Aluno salvo com sucesso!);
msg.setSeverity(FacesMessage.SEVERITY_INFO);
context.addMessage(null, msg);
} catch (RegraNegocioException e) {
// TODO: handle exception
context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,
e.getMessage(), e.getMessage()));
} catch (Exception e) {
FacesMessage msg = new FacesMessage(Erro inesperado ao salvar conta!!);
msg.setSeverity(FacesMessage.SEVERITY_ERROR);
context.addMessage(null, msg);
}
}
public List<SelectItem> getEstados_civil() {
if (this.estados_civil == null) {
this.estados_civil = new ArrayList<SelectItem>();
List<Estado_Civil> estadocivil = new Estado_CivilService().listarTodas();
this.estados_civil.add(new SelectItem(null, Selecione));
for (Estado_Civil Estadocivil : estadocivil) {
this.estados_civil.add(new SelectItem(estadocivil, Estadocivil.getDescricao()));
}
}
return estados_civil;
}
public List<SelectItem> getStatus_aluno() {
if (this.status_aluno == null) {
this.status_aluno = new ArrayList<SelectItem>();
List<Tipo_Status> statusaluno = new Tipo_StatusService().listarTodas();
this.status_aluno.add(new SelectItem(null, Selecione));
for (Tipo_Status Statusaluno : statusaluno) {
this.status_aluno.add(new SelectItem(statusaluno, Statusaluno.getDescricao()));
}
}
return status_aluno;
}
public void setStatus_aluno(List<SelectItem> status_aluno) {
this.status_aluno = status_aluno;
}
public List<SelectItem> getEstado() {
if (this.estado == null) {
this.estado = new ArrayList<SelectItem>();
for (Estado eStado : Estado.values()) {
this.estado.add(new SelectItem(estado, eStado.toString()));
}
}
return estado;
}
/* { public List<SelectItem> getTipo_Documento() {
if (this.tipo_documento == null) {
this.tipo_documento = new ArrayList<SelectItem>();
List<Tipo_Documento> tipodocumento = new Tipo_DocumentoService().listarTodas();
this.tipo_documento.add(new SelectItem(null, Selecione));
for (Tipo_Documento Tipodocumento : tipodocumento) {
this.tipo_documento.add(new SelectItem(tipodocumento, Tipodocumento.getNome()));
}
}
return tipo_documento;
} */
/*
public List<SelectItem> getPessoas() {
if (this.pessoas == null) {
this.pessoas = new ArrayList<SelectItem>();
List<Pessoa> pessoas = new PessoaService().listarTodas();
this.pessoas.add(new SelectItem(null, Selecione));
for (Pessoa pessoa : pessoas) {
this.pessoas.add(new SelectItem(pessoa,
pessoa.getNome()));
}
}
return this.pessoas;
} */
public Aluno getAlunoEdicao() {
return alunoEdicao;
}
public void setAlunoEdicao(Aluno alunoEdicao) {
this.alunoEdicao = alunoEdicao;
}
}
cadastroAluno.jsp
<%--
Document : cadastroAluno
Created on : 23/04/2012, 22:40:47
Author : Gustavo
--%>
<%@ page language=java contentType=text/html; charset=ISO-8859-1
pageEncoding=ISO-8859-1%>
<%@ taglib prefix=f uri=http://java.sun.com/jsf/core%>
<%@ taglib prefix=h uri=http://java.sun.com/jsf/html%>
<%@ taglib uri=http://richfaces.org/a4j prefix=a4j%>
<%@ taglib uri=http://richfaces.org/rich prefix=rich%>
<%@ taglib uri=http://java.sun.com/jsp/jstl/core prefix=c%>
<!DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN http://www.w3.org/TR/html4/loose.dtd>
<html>
<head>
<title>Cadastro de Aluno</title>
<link rel=stylesheet type=text/css href=../css/estilo.css>
</head>
<f:view>
<body>
<h:form id=frm styleClass=formulario>
<h1>
<h:outputText value=Cadastro de alunos />
</h1>
<h:messages layout=table showSummary=true showDetail=false
globalOnly=true styleClass=msgErro infoClass=msgInfo
style=font-weight: bold />
<rich:tabPanel width=100%>
<rich:tab label=Dados Gerais switchType=server>
<h:panelGrid style=text-align: left columns=2>
<h:panelGroup style=text-align: left>
<h:outputLabel value=Código: />
<h:inputText id=codigo size=10
value=#{CadastroAlunoBean.alunoEdicao.cd_aluno}
label=Código do aluno disabled=true />
<h:message for=codigo showSummary=true showDetail=false
styleClass=msgErro />
<br>
<br>
<h:outputLabel value=Nome: />
<h:inputText id=nomeAluno size=80 maxlength=150
value=#{CadastroAlunoBean.alunoEdicao.nome} required=true
label=Nome do Aluno />
<h:message for=nomeAluno showSummary=true showDetail=false
styleClass=msgErro />
<br>
<br>
<h:outputLabel value= Data Nascimento: />
<rich:calendar id=dtNascimento inputSize=12
datePattern=dd/MM/yyyy enableManualInput=true
value=#{CadastroAlunoBean.alunoEdicao.dt_nascimento}
required=true label=Data nascimento />
<h:message for=dtNascimento showSummary=true
showDetail=false styleClass=msgErro />
<br>
<br>
<h:outputLabel value=CPF/CNPJ: />
<h:inputText id=cnpjcpf size=14 maxlength=14
value=#{CadastroAlunoBean.alunoEdicao.cnpj_cpf}
required=true label=CPF/CNPJ>
</h:inputText>
<h:message for=cnpjcpf showSummary=true showDetail=false
styleClass=msgErro />
<br>
<br>
<h:outputLabel value=RG : />
<h:inputText id=rg size=14 maxlength=14
value=#{CadastroAlunoBean.alunoEdicao.rg} required=true
label=RG>
</h:inputText>
<h:message for=rg showSummary=true showDetail=false
styleClass=msgErro />
<br>
<br>
<h:outputLabel value=Orgão Emissor : />
<h:inputText id=OrgEmiss size=14 maxlength=14
value=#{CadastroAlunoBean.alunoEdicao.rg_orgao}
required=true label=Orgão Emissor>
</h:inputText>
<h:message for=OrgEmiss showSummary=true showDetail=false
styleClass=msgErro />
<br>
<br>
<h:outputLabel value=Nome do Pai : />
<h:inputText id=NomPai size=80 maxlength=80
value=#{CadastroAlunoBean.alunoEdicao.filiacao_pai}
required=true label=Nome do Pai>
</h:inputText>
<h:message for=NomPai showSummary=true showDetail=false
styleClass=msgErro />
<br>
<br>
<h:outputLabel value=Estado Civil : />
<h:selectOneMenu id=EstCivil
value=#{CadastroAlunoBean.alunoEdicao.estado_civil}
label=EstCivil required=true>
<f:selectItems value=#{CadastroAlunoBean.estados_civil} />
</h:selectOneMenu>
<h:message for=EstCivil showSummary=true showDetail=false
styleClass=msgErro />
<br>
<br>
<h:outputLabel value=Nome da Mãe : />
<h:inputText id=NomMae size=80 maxlength=80
value=#{CadastroAlunoBean.alunoEdicao.filiacao_mae}
required=true label=Nome da Mãe>
</h:inputText>
<h:message for=NomMae showSummary=true showDetail=false
styleClass=msgErro />
<br>
<br>
<h:outputLabel value=Status do aluno : />
<h:selectOneMenu id=StatusAlu
value=#{CadastroAlunoBean.alunoEdicao.cd_status }
label=StatusAlu required=true>
<f:selectItems value=#{CadastroAlunoBean.status_aluno} />
</h:selectOneMenu>
<h:message for=StatusAlu showSummary=true showDetail=false
styleClass=msgErro />
<br>
<br>
<h:outputLabel value=Naturalidade : />
<h:inputText id=natural size=14 maxlength=14
value=#{CadastroAlunoBean.alunoEdicao.naturalidade}
required=true label=Naturalidade>
</h:inputText>
<br>
<br>
<h:outputLabel value=Nacionalidade : />
<h:inputText id=nacional size=14 maxlength=14
value=#{CadastroAlunoBean.alunoEdicao.nacionalidade}
required=true label=Nacionalidade>
</h:inputText>
</h:panelGroup>
</h:panelGrid>
</rich:tab>
<rich:tab label=Endereço switchType=client>
<h:panelGrid style=text-align: left columns=2>
<h:panelGroup style=text-align: left>
<h:outputLabel value=CEP : />
<h:inputText id=cep size=14 maxlength=10
value=#{CadastroAlunoBean.alunoEdicao.cep} required=true
label=Nacionalidade
validatorMessage=O valor informado não obedece ao padrão definido>
<f:validateRegex pattern=(^[0-9]\.?[0-9]-[0-9]) />
</h:inputText>
<br>
<br>
<h:outputLabel value=Endereço : />
<h:inputText id=endereco size=80 maxlength=200
value=#{CadastroAlunoBean.alunoEdicao.endereco}
required=true label=Endereço>
</h:inputText>
<br>
<br>
<h:outputLabel value=Bairro : />
<h:inputText id=bairro size=50 maxlength=60
value=#{CadastroAlunoBean.alunoEdicao.bairro} required=true
label=Bairro>
</h:inputText>
<br>
<br>
<h:outputLabel value=Complemento : />
<h:inputText id=complemento size=80 maxlength=200
value=#{CadastroAlunoBean.alunoEdicao.complemento}
required=true label=Complemento>
</h:inputText>
<br>
<br>
<h:outputLabel value=Cidade : />
<h:inputText id=cidade size=50 maxlength=60
value=#{CadastroAlunoBean.alunoEdicao.cidade} required=true
label=Cidade>
</h:inputText>
<br>
<br>
<h:outputLabel value=Estado : />
<h:selectOneMenu id=Estado
value=#{CadastroAlunoBean.alunoEdicao.estado }
label=EstCivil required=true>
<f:selectItems value=#{CadastroAlunoBean.estado} />
</h:selectOneMenu>
<h:message for=Estado showSummary=true showDetail=false
styleClass=msgErro />
</h:panelGroup>
</h:panelGrid>
</rich:tab>
<rich:tab label=Endereço de Cobrança switchType=client>
<h:panelGrid style=text-align: left columns=2>
<h:panelGroup style=text-align: left>
<h:outputLabel value=CEP : />
<h:inputText id=cep_cob size=14 maxlength=14
value=#{CadastroAlunoBean.alunoEdicao.cob_cep }
required=true label=CEP
validatorMessage=O valor informado não obedece ao padrão definido>
<f:validateRegex pattern=(^[0-9]\.?[0-9]-[0-9]) />
</h:inputText>
<br>
<br>
<h:outputLabel value=Endereço : />
<h:inputText id=endereco_cob size=80 maxlength=200
value=#{CadastroAlunoBean.alunoEdicao.cob_endereco}
required=true label=Endereço>
</h:inputText>
<br>
<br>
<h:outputLabel value=Bairro : />
<h:inputText id=bairro_cob size=50 maxlength=60
value=#{CadastroAlunoBean.alunoEdicao.cob_bairro}
required=true label=Bairro>
</h:inputText>
<br>
<br>
<h:outputLabel value=Complemento : />
<h:inputText id=complemento_cob size=80 maxlength=200
value=#{CadastroAlunoBean.alunoEdicao.cob_complemento}
required=true label=Complemento>
</h:inputText>
<br>
<br>
<h:outputLabel value=Cidade : />
<h:inputText id=cidade_cob size=50 maxlength=60
value=#{CadastroAlunoBean.alunoEdicao.cob_cidade}
required=true label=Cidade>
</h:inputText>
<br>
<br>
<h:outputLabel value=Estado : />
<h:selectOneMenu id=Estado_cob
value=#{CadastroAlunoBean.alunoEdicao.cob_estado }
label=EstCivil required=true>
<f:selectItems value=#{CadastroAlunoBean.estado} />
</h:selectOneMenu>
<h:message for=Estado showSummary=true showDetail=false
styleClass=msgErro />
</h:panelGroup>
</h:panelGrid>
</rich:tab>
<rich:tab label=Contatos switchType=client>
<h:panelGrid style=text-align: left columns=2>
<h:panelGroup style=text-align: left>
<h:outputLabel value=Telefone : />
<h:inputText id=telefone size=14 maxlength=14
value=#{CadastroAlunoBean.alunoEdicao.telefone1}
required=true label=Telefone>
</h:inputText>
<br>
<br>
<h:outputLabel value=Site : />
<h:inputText id=site size=80 maxlength=100
value=#{CadastroAlunoBean.alunoEdicao.site} required=true
label=Site>
</h:inputText>
<br>
<br>
<h:outputLabel value=Telefone : />
<h:inputText id=telefone2 size=14 maxlength=14
value=#{CadastroAlunoBean.alunoEdicao.telefone2}
required=true label=Telefone>
</h:inputText>
<br>
<br>
<h:outputLabel value=Email : />
<h:inputText id=email size=80 maxlength=100
value=#{CadastroAlunoBean.alunoEdicao.email} required=true
label=Email>
</h:inputText>
<br>
<br>
<h:outputLabel value=Telefone : />
<h:inputText id=telefone3 size=14 maxlength=14
value=#{CadastroAlunoBean.alunoEdicao.telefone3}
required=true label=Telefone>
</h:inputText>
</h:panelGroup>
</h:panelGrid>
</rich:tab>
<rich:tab label=Cursos switchType=client>
<h:panelGrid style=text-align: left columns=2>
<h:panelGroup style=text-align: left>
<h:outputLabel value=Data Desistência : />
<rich:calendar id=dtDesistencia inputSize=12
datePattern=dd/MM/yyyy enableManualInput=true
value=#{CadastroAlunoBean.alunoEdicao.dt_desistencia}
required=false label=Data Desistência />
<h:message for=dtDesistencia showSummary=true
showDetail=false styleClass=msgErro />
<br>
<br>
<h:outputLabel value=Data Trancamento : />
<rich:calendar id=dtTrancamento inputSize=12
datePattern=dd/MM/yyyy enableManualInput=true
value=#{CadastroAlunoBean.alunoEdicao.dt_trancamento}
required=false label=Data Trancamento />
<h:message for=dtTrancamento showSummary=true
showDetail=false styleClass=msgErro />
<br>
<br>
<h:outputLabel value=Data Conclusão Curso : />
<rich:calendar id=dtConclusaoCurso inputSize=12
datePattern=dd/MM/yyyy enableManualInput=true
value=#{CadastroAlunoBean.alunoEdicao.dt_conclusao_curso}
required=false label=Data Conclusão Curso />
<h:message for=dtConclusaoCurso showSummary=true
showDetail=false styleClass=msgErro />
</h:panelGroup>
</h:panelGrid>
</rich:tab>
<rich:tab label=Documentos switchType=client>
<h:panelGrid style=text-align: left-top columns=2>
<h:outputLabel value=Documentos : />
<rich:dataTable rows=10 id=tab
value=#{CadastroAlunoBean.alunoEdicao.documentos} var=item
width=790px>
<rich:column style=text-aling: center>
<f:facet name=header>
<h:outputText value=Documento />
</f:facet>
<h:outputText value=#{item.nome} />
</rich:column>
</rich:dataTable>
</h:panelGrid>
</rich:tab>
<rich:tab label=Observação switchType=client>
<h:panelGrid style=text-align: left-top columns=2>
<h:outputLabel value=Observação : />
<h:panelGroup style=text-align: left-top>
<h:inputTextarea id=observacao
value=#{CadastroAlunoBean.alunoEdicao.observacao}
required=true label=Observação rows=10 cols=60>
</h:inputTextarea>
</h:panelGroup>
</h:panelGrid>
</rich:tab>
</rich:tabPanel>
<!------ Botões ----->
<h:panelGroup>
<a4j:commandButton value=Salvar
actionListener=#{CadastroAlunoBean.salvar} reRender=frm
type=submit />
<a4j:commandButton value=Cancelar action=menu immediate=true />
</h:panelGroup>
</h:form>
</body>
</f:view>
</html>
Desde já agradeço a ajuda
Gustavo Bernardino
Curtir tópico
+ 0Posts
29/05/2012
Davi Costa
private Set<Turmas> turma = new HashSet<Turmas>(0);
no model??????
Seu modleo deve ser o mais simples e genérico possível, que precisar desse atributo que instancie ele!
busque sempre usar pojo no modelo
http://blog.rodrigoallemand.com.br/?tag=pojo
att Davi
Gostei + 0
29/05/2012
Gustavo Bernardino
Eu não quero listar tudo isso não. O que quero mesmo é listar os documento de um somente só Aluno.
Esta estrutura que você questionou realmente já foram teste meus já até removi.
Alterei conforme uma ajuda que você deu a outro companheiro aqui do fórum.
Vi pelo SQL do hibernate que ele selecionou, mas não preencheu a Coleção como faço agora para lista-lo no datatable???
Gostei + 0
30/05/2012
Davi Costa
Então no caso quando ele já estiver na base e vc carregá-lo e que vc queria ver não é isso?
Se quando ao salvar vc quiser vendo esse objeto terá que tirar o new de alunoEdicao e atualizar a tab que mostra os documentos.
Caso o escopo do seu bean perca o objeto aluno selecionado, sugiro que use o a4j:keepalive
att Davi
Gostei + 0
30/05/2012
Gustavo Bernardino
O problema não é gravar e atualizar é somente pegar estes dados e exibir na edição , entende??? Cloquei aqui novamente as classes agora claro reduzidas para melhor visualização e nos lugares envolvidos no problema.
Quero somente exibir os documentos do aluno, ele agora realiza o select do relacionamento das 3 tabelas pois esta sainda no console eu verifiquei, a coleção é criada mas não é persistida. o que devo fazer ??? Devo cria um método para consultar o getdocumentos() em Alunos??? já estou sem sabe o que fazer!!!
**** Classe Aluno.java ****
@Entity
@Table(name=alunos)
public class Aluno implements Serializable {
...
private Collection<Tipo_Documento> documentos ;
...
@ManyToMany(fetch=FetchType.EAGER )
@JoinTable(name = alunos_documentos, joinColumns = { @JoinColumn(name = cd_alunos_fk) },
inverseJoinColumns={@JoinColumn(name=cd_documento)})
@Fetch(FetchMode.SUBSELECT)
public Collection<Tipo_Documento> getDocumentos() {
return this.documentos;
}
public void setDocumentos(Collection<Tipo_Documento> documentos) {
this.documentos = documentos;
}
...
*********** Classe CadastroAlunoBean.java ***
public class CadastroAlunoBean {
...
private Collection<Tipo_Documento> documentos;
...
public Collection<Tipo_Documento> getDocumentos() {
return documentos;
}
...
***** Clasee cadastroAluno.jsp ----
<html>
<head>
<title>Cadastro de Aluno</title>
<link rel=stylesheet type=text/css href=../css/estilo.css>
</head>
<f:view>
<body>
<h:form id=frm styleClass=formulario>
<h1>
<h:outputText value=Cadastro de alunos />
</h1>
...
<rich:dataTable rows=10 id=tab
value=#{CadastroAlunoBean.alunoEdicao.documentos} var=item width=790px>
<rich:column style=text-aling: center>
<f:facet name=header>
<h:outputText value=Documento />
</f:facet>
<h:outputText value=#{item.???????? } />
</rich:column>
</rich:dataTable>
Gostei + 0
30/05/2012
Davi Costa
Foca nisso que provavelmente vai resolver seus problemas.
Vc na tela ao inserir um aluno adiciona uma lista de documentos?
Se sim esses documentos já estão persistidos no banco, pois precisam estar,senão irão nulos mesmo
att Davi
Gostei + 0
30/05/2012
Gustavo Bernardino
Também pode ser mesmo a persistência no banco, mas o que pode causar isso???
Tenho as 3 tabelas :
Aluno
Tipo documento
alunos_documentos
em alunos_documentos tenho :
cd_alunos_fk
cd_documento_fk
na estrutura esta campos são claro chave estrangeira de cada uma das tabela acima. ele me exibe um obejto com mais ou menso 10 ocorrencias tudo null.
Ontem eu alterei criando um getdocumento mas no cadastroAlunobean onde eu pagaria um list do Tipo_documento mas do Getdocumento de aluno ele me retornou todos os dados de tipo_documentos e ai???
onde pode ser o problema???
To ferrado!!
Gostei + 0
30/05/2012
Davi Costa
vc precisar tero tipoDocumento salvo no banco.
Ao inserir um aluno, vc adiciona a lista de tipoDocumento os tipodocumento q o usuário escolhe na tela vindo do seu banco.
Ai sim vc pode inserir o aluno que vai ficar tudo 100%
att Davi
Gostei + 0
30/05/2012
Gustavo Bernardino
Esta é somente a edição, os dados existem no banco, tanto é que quando estou testando eu tenho um aluno que tem vários documentos, não é na gravação isso tudo é quando explodo os dados do aluno e vou deseja alterar algo , entende???
Seria como se eu quisesse resgatar e exibir os dados só, uma consulta !
Gostei + 0
30/05/2012
Davi Costa
att Davi
Gostei + 0
30/05/2012
Gustavo Bernardino
Olha já sim, é por isso que te falei que ele cria o collection documentos só que não vejo os dados referentes ao alunos mas vejo o código do aluno que ele envia para selecionar .
Eu preciso fazer um métodos em ALunoService para carregar esta lista ou só na consulte de alunoEdicao ele já deveria carregar os dados???
Se preciso poderia enviar um exemplo??
Olha tenho msn caso queira me adiciona
gustavo_hmb@hotmail.com
Gostei + 0
30/05/2012
Davi Costa
confere se o objeto n passa pelo construtor e vc sempre dá um new nele,
vc deixou eager então já épara vir a lista da base, vc tem que entender a ciclo de vida do jsf... e segundo.. pq n usa o keepalive para manter o estado do objeto
a rede aki barra msn :/
att Davi
Gostei + 0
30/05/2012
Gustavo Bernardino
Ou na classe CadastroAlunoBean?
pois em nenhuma tenho um construtor!!
Gostei + 0
30/05/2012
Davi Costa
att Davi
Gostei + 0
30/05/2012
Gustavo Bernardino
public class CadastroAlunoBean {
private Aluno alunoEdicao;
//private List<Tipo_Documento> Lsttipo_documento = new ArrayList<Tipo_Documento>();
private List<SelectItem> estados_civil;
private List<SelectItem> status_aluno;
private List<SelectItem> estado;
private Collection<Tipo_Documento> documentos;
....
e se preciso colocar um método no bean para buscar os valores para documentos???
desde já agradeço
Gostei + 0
30/05/2012
Gustavo Bernardino
Boa Noite, cara descobri qual era o problema veja:
Classe Aluno.java(Entidade)
No erro :
@ManyToMany(fetch=FetchType.EAGER )
@JoinTable(name = alunos_documentos, joinColumns = { @JoinColumn(name = cd_alunos_fk) },
inverseJoinColumns={@JoinColumn(name=cd_documento)})<== errado Este é o campo da Tabela TIPO_DOCUMENTOS
@Fetch(FetchMode.SUBSELECT)
public Collection<Tipo_Documento> getDocumentos() {
return this.documentos;
}
Após o erro :
@ManyToMany(fetch=FetchType.EAGER )
@JoinTable(name = alunos_documentos, joinColumns = { @JoinColumn(name = cd_alunos_fk) },
inverseJoinColumns={@JoinColumn(name=cd_documento_fk)}) <== SOMENTE ISSO (ESTE É O CAMPO DA TABELA DE MEIO DE CAMPO) @Fetch(FetchMode.SUBSELECT)
public Collection<Tipo_Documento> getDocumentos() {
return this.documentos;
}
Eu tinha mapeado antes com o campo da tabela TIPO_DOCUMENTO na anotação inverseJoinColumns={@JoinColumn
por isso ele criada o objeto AlunoEdição e não persistia o objeto documentos
Davi muito obrigado pela sua Atenção e paciência!!
Nota 10 pra você!! Valeu
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)