Boa Noite Caros!
Estou tendo problemas em popular o combobox na pagina web, por min está tudo certo, entretanto ele mostra
esse erro: HTTP Status 500 - /cadastro_jogador.xhtml @41,45 value="#{jogadorBean.listaTimes}": Property 'listaTimes' not found on type futebol.bean.JogadorBean.
Eu segui esse tutorial aqui: http://www.arquivodecodigos.net/dicas/jsf-java-server-faces-como-preencher-um-controle-hselectonemenu-com-informacoes-de-uma-tabela-do-banco-de-dados-3148.html , nesse tutorial ele mostra passo a passo como compor um combox, mas comigo não deu muito certo.
Obs.: Eu utilizei hibernate, no entanto eu testei via console, e ele está funcionado corretamente.
O código pode ser visualizado abaixo:
//BEAN//package futebol.bean;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import futebol.entities.JogadorEntity;
import futebol.entities.TimeEntity;
import futebol.repository.JogadorRepository;
import futebol.repository.TimeRepository;
@ManagedBean
public class JogadorBean implements Serializable {
TimeEntity time = new TimeEntity();
private static final long serialVersionUID = 1L;
private String nome;
private int idade;
private float altura;
private TimeEntity time_id;
public JogadorBean()
{
}
public List<TimeEntity> getTimes() {
EntityManagerFactory factory = Persistence
.createEntityManagerFactory("futebol");
EntityManager gerenciador = factory.createEntityManager();
List<TimeEntity> listaTimes = new ArrayList<TimeEntity>();
try {
TimeRepository tr = new TimeRepository(gerenciador);
for (TimeEntity obj : tr.buscaTodos()) {
listaTimes.add(obj);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
gerenciador.close();
factory.close();
}
return listaTimes;
}
public void cadastrarJogador() {
EntityManagerFactory factory = Persistence
.createEntityManagerFactory("futebol");
EntityManager gerenciador = factory.createEntityManager();
try {
JogadorEntity jogador = new JogadorEntity();
jogador.setNome(nome);
jogador.setIdade(idade);
jogador.setAltura(altura);
jogador.setTime(time);
JogadorRepository jr = new JogadorRepository(gerenciador);
gerenciador.getTransaction().begin();
jr.adiciona(jogador);
gerenciador.getTransaction().commit();
} catch (Exception e) {
e.printStackTrace();
} finally {
factory.close();
gerenciador.close();
}
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public int getIdade() {
return idade;
}
public void setIdade(int idade) {
this.idade = idade;
}
public float getAltura() {
return altura;
}
public void setAltura(float altura) {
this.altura = altura;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
public TimeEntity getTime_id() {
return time_id;
}
public void setTime_id(TimeEntity time_id) {
this.time_id = time_id;
}
}
//PaginaWeb//
<?xml version="1.0" encoding="ISO-8859-1" ?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" version="2.0">
<jsp:directive.page language="java"
contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" />
<jsp:text>
<![CDATA[ <?xml version="1.0" encoding="ISO-8859-1" ?> ]]>
</jsp:text>
<jsp:text>
<![CDATA[ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> ]]>
</jsp:text>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Cadastro de Jogador</title>
</head>
<body>
<f:view>
<h:form>
<center>
<table>
<caption><p style="font-weight:bold; font-size: 22px; align-text:center; ">Cadastro de jogador:</p></caption>
<tr>
<td><h:outputLabel value="Nome:" for="txtNome" /></td>
<td><h:inputText maxlength="50" value="#{jogadorBean.nome}" id="txtNome" /></td>
</tr>
<tr>
<td><h:outputLabel value="Idade:" for="txtIdade" /></td>
<td><h:inputText maxlength="4" value="#{jogadorBean.idade}" id="txtIdade" /></td>
</tr>
<tr>
<td><h:outputLabel value="Altura:" for="txtAltura" /></td>
<td><h:inputText maxlength="5" value="#{jogadorBean.altura}" id="txtAltura" /></td>
</tr>
<tr>
<td>
<h:selectOneListbox id="times" value="#{jogadorBean.time_id}">
<f:selectItems value="#{jogadorBean.listaTimes}"
var="jogadorEntity"
itemValue="#{jogadorEntity.id}"
itemLabel="#{jogadorEntity.nome}"/>
</h:selectOneListbox>
</td>
</tr>
<tr>
<td>
<h:commandButton value="Salvar Jogador" action="#{jogadorBean.cadastrarJogador}" />
<br />
</td>
</tr>
</table>
</center>
</h:form>
</f:view>
</body>
</html>
</jsp:root>
Achei um tutorial na internet para adicionar a tag
"vc-complex-type.2.4.b: The content of element 'managed-bean' is not complete. One of '{"http://java.sun.com/
xml/ns/javaee":description, "http://java.sun.com/xml/ns/javaee":display-name, "http://java.sun.com/xml/ns/
javaee":icon, "http://java.sun.com/xml/ns/javaee":managed-bean-name}' is expected."
Achei em um outro forum, falando que precisa ser um atributo para a tag
achei um tutorial que uma pessoa utilizou list para popular e outra que não pensei em nenhuma ideia com uma lógica adequada até o exato momento presente para solucionar isso.
Dessa forma, fico sem nenhuma ideia para resolver meu problema.
Alguém teve alguma ideia ou teve um problema semelhante?
Muito obrigado,
Att, André Vieira.