0
I have a selectOneMenu
which will be used to list all Generations (data in the database). These data should be listed when registering a Nature object. My selectOneMenu
is 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 carry all the Generations in mine selectOneMenu
?
Have you looked at the example in the documentation? http://www.primefaces.org/showcase/ui/input/oneMenu.xhtml Can you detail which part of the example you don’t understand? And, man, take these off Try-catch from there, please!! hehehe
– Caffé
rsrsrs.... Which Try/catch ?
– Roknauta
@Caffé I had even looked at this example...but I did not understand well the part to pull from the bank, etc., I created a Converter already.
– Roknauta
Your question is how to pull from the bank or how to display on the screen? The page code seems correct. In Java, you have to do something like
return geracoesDao.findAll()
in thegetGeracoes
.– Caffé
@Caffé right.... but in this case we do not use the convert ?
– Roknauta