I have selectOneMenu
that will serve to list all Generations (data in the database). These data must be listed at the time of registering a Nature object. My selectOneMenu
looks like this:
<h:outputLabel value="#{msg['geracao']}" />
<p:selectOneMenu id="geracao" value="#{msg['geracao']}">
<f:selectItem value="" />
<f:selectItems value="#{naturemb.geracoes}"/>
</p:selectOneMenu>
<p:message for="geracao" />
The Nature Controller looks like this:
package br.com.pokemax.controle;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.inject.Inject;
import br.com.pokemax.modelo.Geracao;
import br.com.pokemax.modelo.Nature;
import br.com.pokemax.negocio.NatureDAO;
import br.com.pokemax.util.MensagensUtil;
@ViewScoped
@ManagedBean(name = "naturemb")
public class ControleNature implements Serializable {
private static final long serialVersionUID = 1L;
private Nature nature;
@Inject
private NatureDAO dao;
private List<Nature> lista;
private List<Geracao> geracoes;
@PostConstruct
public void inicio() {
}
public void novo() {
nature = new Nature();
}
public void gravar() {
try {
if (nature.getId() == null) {
dao.insert(nature);
MensagensUtil.msg("Info", "cadastro.sucesso", new Object[] { MensagensUtil.get("nature") });
nature = new Nature();
} else {
dao.update(nature);
MensagensUtil.msg("Info", "alterado.sucesso", new Object[] { MensagensUtil.get("nature") });
}
} catch (Exception e) {
e.getMessage();
return;
}
}
public void pesquisar() {
try {
lista = dao.findAll();
} catch (Exception e) {
e.printStackTrace();
}
}
public void excluir(Nature h) {
try {
dao.delete(h);
MensagensUtil.msg("Info", "removido.sucesso", new Object[] { MensagensUtil.get("nature") });
pesquisar();
} catch (Exception e) {
e.getMessage();
}
}
public void editar(Long id) {
try {
setNature(dao.find(id));
} catch (Exception e) {
e.getMessage();
}
}
public void cancelar() {
nature = null;
}
public Nature getNature() {
return nature;
}
public List<Geracao> getGeracoes() {
return geracoes;
}
public void setGeracoes(List<Geracao> geracoes) {
this.geracoes = geracoes;
}
public void setNature(Nature nature) {
this.nature = nature;
}
public List<Nature> getLista() {
return lista;
}
public void setLista(List<Nature> lista) {
this.lista = lista;
}
}
How do I load all Generations in my selectOneMenu
?