Pessoal,
já tenho 2 dias tentando resolver isso e não consigo, quero criar uma opção onde se faz uma busca dos alunos, seleciona o desejado e depois eu insiro ele em uma tabela. Mas eu já fiz diversas pesquisas e alterações e nunca consigo obter o objeto que foi selecionado, seguem os meus códigos, quem puder me dar uma luz vou agradecer muito.
package aprender.bean;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
/**
*
* @author raniere.sousa
*/
@ManagedBean
@RequestScoped
public class AlunoBean {
private String matricula;
private String nome;
private String turma;
private String sede;
private String foto;
private String auto; /** Creates a new instance of AlunoBean */
public AlunoBean()
{
}
public AlunoBean(String wmatricula,String wnome,String wturma,String wsede,String wfoto,String wauto)
{
this.matricula = wmatricula;
this.nome = wnome;
this.turma = wturma;
this.sede = wsede;
this.foto = wfoto;
this.auto = wauto;
}
/**
* @return the matricula
*/
public String getMatricula() {
return matricula;
}
/**
* @param matricula the matricula to set
*/
public void setMatricula(String matricula) {
this.matricula = matricula;
}
/**
* @return the nome
*/
public String getNome() {
return nome;
}
/**
* @param nome the nome to set
*/
public void setNome(String nome) {
this.nome = nome;
}
/**
* @return the turma
*/
public String getTurma() {
return turma;
}
/**
* @param turma the turma to set
*/
public void setTurma(String turma) {
this.turma = turma;
}
/**
* @return the sede
*/
public String getSede() {
return sede;
}
/**
* @param sede the sede to set
*/
public void setSede(String sede) {
this.sede = sede;
}
/**
* @return the foto
*/
public String getFoto() {
return foto;
}
/**
* @param foto the foto to set
*/
public void setFoto(String foto) {
this.foto = foto;
}
/**
* @return the auto
*/
public String getAuto() {
return auto;
}
/**
* @param auto the auto to set
*/
public void setAuto(String auto) {
this.auto = auto;
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package aprender.bean;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import java.util.ArrayList;
import aprender.bean.AlunoBean;
import java.sql.*;
import aprender.util.AcessoBanco;
import javax.faces.context.FacesContext;
import javax.faces.application.FacesMessage;
/**
*
* @author raniere.sousa
*/
@ManagedBean
@RequestScoped
public class PesquisaAluno {
private ArrayList ListadeAlunos = new ArrayList<AlunoBean>();
private ArrayList ListadeAlunosSel = new ArrayList<AlunoBean>();
private AlunoBean alunoaux;
private AlunoBean alunosel;
private AcessoBanco acesso;
private String nomebuscar;
private boolean mostratabela = false;
/** Creates a new instance of PesquisaAluno */
public PesquisaAluno() {
}
public void BuscaAlunos() {
try
{
ListadeAlunos.clear();
acesso = new AcessoBanco();
ResultSet rs = acesso.Executar("SELECT * FROM VW_ALUNOS_PESQUISA WHERE NOME LIKE '%"+nomebuscar+"%'");
while (rs.next())
{
setAlunoaux(new AlunoBean(rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5), rs.getString(6)));
ListadeAlunos.add(getAlunoaux());
}
this.setMostratabela(true);
}
catch (Exception e)
{
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,"Erro de conexão ao Banco", e.toString()));
}
}
/**
* @return the ListadeAlunos
*/
public ArrayList getListadeAlunos() {
return ListadeAlunos;
}
/**
* @return the nomebuscar
*/
public String getNomebuscar() {
return nomebuscar;
}
/**
* @param nomebuscar the nomebuscar to set
*/
public void setNomebuscar(String nomebuscar) {
this.nomebuscar = nomebuscar;
}
/**
* @return the mostratabela
*/
public boolean isMostratabela() {
return mostratabela;
}
/**
* @param mostratabela the mostratabela to set
*/
public void setMostratabela(boolean mostratabela) {
this.mostratabela = mostratabela;
}
/**
* @return the ListadeAlunosSel
*/
public ArrayList getListadeAlunosSel() {
return ListadeAlunosSel;
}
public void AdicionaAlunoSel()
{
ListadeAlunosSel.add(getAlunosel());
alunoaux = new AlunoBean("0000","Raniere","0","0","0","0");
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,"Erro de conexão ao Banco", "teste"+ListadeAlunosSel.size()+alunoaux.getNome()));
}
/**
* @return the alunoaux
*/
public AlunoBean getAlunoaux() {
return alunoaux;
}
/**
* @param alunoaux the alunoaux to set
*/
public void setAlunoaux(AlunoBean alunoaux) {
this.alunoaux = alunoaux;
}
/**
* @return the alunosel
*/
public AlunoBean getAlunosel() {
return alunosel;
}
/**
* @param alunosel the alunosel to set
*/
public void setAlunosel(AlunoBean alunosel) {
this.alunosel = alunosel;
}
}
<?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"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
Hello from Facelets
<h:form id="form" >
<h:panelGrid columns="4" style="margin-bottom:10px; font-size:12px ">
<h:outputLabel for="editbusca" value="Nome:" style=" font-weight: bold" />
<p:inputText id="editbusca" value="#{pesquisaAluno.nomebuscar}" />
<p:commandButton value="Buscar" update="tabalunos" action="#{pesquisaAluno.BuscaAlunos}" />
<p:ajaxStatus style="width:16px;height:16px;">
<f:facet name="start">
<h:graphicImage value="ajaxloader.gif" />
</f:facet>
<f:facet name="complete">
<h:outputText value="" />
</f:facet>
</p:ajaxStatus>
</h:panelGrid>
<h:panelGrid id="tabalunos">
<p:messages id="msgs" showDetail="true"/>
<p:dataTable id="tablepesq" var="alunoBean" value="#{pesquisaAluno.listadeAlunos}" selection="#{pesquisaAluno.alunosel}" selectionMode="single"
style="font-size:10px " rendered="#{pesquisaAluno.mostratabela}" paginator="true" rows="10" >
<p:column>
<f:facet name="header" >
Matrícula
</f:facet>
<h:outputText value="#{alunoBean.matricula}" />
</p:column>
<p:column>
<f:facet name="header">
Nome
</f:facet>
<h:outputText value="#{alunoBean.nome}" />
</p:column>
<p:column>
<f:facet name="header">
Série
</f:facet>
<h:outputText value="#{alunoBean.turma}" />
</p:column>
<p:column>
<f:facet name="header">
Sede
</f:facet>
<h:outputText value="#{alunoBean.sede}" />
</p:column>
<p:column>
<f:facet name="header">
Possui Foto
</f:facet>
<h:outputText value="#{alunoBean.foto}" />
</p:column>
<p:column>
<f:facet name="header">
Autorizado
</f:facet>
<h:outputText value="#{alunoBean.auto}" />
</p:column>
</p:dataTable>
</h:panelGrid>
<p:commandButton value="Submit" update=":display" action="#{pesquisaAluno.AdicionaAlunoSel}" oncomplete="dlg.hide();"/>
<p:commandButton value="Testar" update="form:pnteste" oncomplete="DialogoRan.show()" >
</p:commandButton>
<p:dialog header="Testando cara" widgetVar="DialogoRan">
<h:panelGrid id="pnteste" >
<p:messages id="msgtst" showDetail="true"/>
<h:outputText value="Nome do Aluno" />
<h:outputText value="#{pesquisaAluno.alunosel.nome}" />
</h:panelGrid>
</p:dialog>
</h:form>
</h:body>
</html>
Não sei o que acontece mas o Ajax da paginação também não funciona.
Grato pela ajuda.