Boa tarde pessoal,
Estou estudando o JSF e estou com um problema de iniciante acredito eu. Eu tenho uma managedBean que tem possui uma lista de objetos, porém não consigo visualizar na página xhmtl. seguem os códigos.
package model;
public class Personagem {
private String name;
private int lvl;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getLvl() {
return lvl;
}
public void setLvl(int lvl) {
this.lvl = lvl;
}
}
@ManagedBean
@ViewScoped
public class PersonagemBean {
private List<Personagem> chars = new ArrayList<Personagem>();
private Personagem personagem = new Personagem();
public PersonagemBean(){
Personagem p = new Personagem();
p.setName("Oberyn");
p.setLvl(1);
this.chars.add(p);
p = new Personagem();
p.setName("Sansa");
p.setLvl(1);
this.chars.add(p);
}
public List<Personagem> getChars() {
return chars;
}
public void setChars(List<Personagem> chars) {
this.chars = chars;
}
public Personagem getPersonagem() {
return personagem;
}
public void setPersonagem(Personagem personagem) {
this.personagem = personagem;
}
form.xhtml
<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:body>
<h:form>
<h:panelGrid columns="2">
<h:outputLabel value="Nome:" for="campo-name"/>
<h:inputText value="#{personagemBean.personagem.name}"
id="campo-name" />
<h:outputLabel value="Lvl" for="campo-lvl"/>
<h:inputText value="#{personagemBean.personagem.lvl}"
id="campo-lvl" />
<h:commandButton value="Adicionar"
action="#{personagemBean.adicionaPersonsagem}"/>
</h:panelGrid>
</h:form>
<h:panelGroup >
<h1>Lista de Personagens</h1>
<ul>
<ui:repeat var="#{personagemBean.chars}" value="personagem">
<li><h:outputText
value="#{personagem.name} #{personagem.lvl}"/> </li>
</ui:repeat>
</ul>
</h:panelGroup>
</h:body>
</html>
Quem puder me auxiliar, agradeço desde já.
