8
I’m creating a page that has to be 3 SelectOneMenu
of the first faces.
In the first I will carry a center (of the university), the second will carry an edict and the third would carry the disciplines of that edict.
The first SelectOneMenu
works, when I change option it loads only the edits of that option. But when I change the option of the second SelectOneMenu
he no longer calls the method. Why isn’t he calling the method? What’s the error? Follow the codes:
deferirInscricoes.xhtml
<h:form id="formInscricoes">
<p:selectOneMenu id="selectCentro" value="#{inscricaoBean.centroSelecionado}" converter = "centroConverter">
<f:selectItem itemValue="#{null}" itemLabel="- Selecione um Centro -" />
<f:selectItems value="#{inscricaoBean.listaCentros}" var="centro" itemValue="#{centro}" itemLabel="#{centro.nome}"/>
<p:ajax event="change" process="@this" listener="#{inscricaoBean.carregaEditais}" update="selectEdital" />
</p:selectOneMenu>
<p:selectOneMenu id="selectEdital" value="#{inscricaoBean.editalSelecionado}" converter = "editalConverter">
<f:selectItem itemValue="#{null}" itemLabel="- Selecione um Edital -" />
<f:selectItems value="#{inscricaoBean.listaEditaisPorCentro}" var="edital" itemValue="#{edital}" itemLabel="#{edital.titulo}"/>
<p:ajax event="change" process="@this" listener="#{inscricaoBean.carregaDisciplinas}" update="selectDisciplinas" />
</p:selectOneMenu>
<p:selectOneMenu id="selectDisciplinas" value="#{inscricaoBean.disciplinaSelecionada}" converter = "disciplinaConverter">
<f:selectItem itemValue="#{null}" itemLabel="- Selecione uma Disciplina -" />
<f:selectItem itemValue="#{null}" itemLabel="- Teste -" />
<f:selectItems value="#{inscricaoBean.listaDisciplinaPorEdital}" var="disciplina" itemValue="#{disciplina}" itemLabel="#{disciplina.nome}"/>
</p:selectOneMenu>
<h:form>
inscribed on Bible.java
private List<Centro> listaCentros;
private List<Edital> listaEditaisPorCentro;
private List<Disciplina> listaDisciplinaPorEdital;
CentroDAO centroDAO = new CentroDAO();
EditalDAO editalDAO = new EditalDAO();
DisciplinaDAO disciplinaDAO = new DisciplinaDAO();
private Centro centroSelecionado;
private Edital editalSelecionado;
private Disciplina disciplinaSelecionada;
// Todos os getters e setters acima foram criado no padrão.
public void carregaEditais() {
System.out.println("Editais carregados.");
listaEditaisPorCentro = editalDAO.getListaEdital(centroSelecionado);
}
public void carregaDisciplinas() {
System.out.println("Disciplinas carregadas.");
listaDisciplinaPorEdital = disciplinasDAO.getListaDisciplinaPorEdital(edital);
}
}
Centroconverter.java
@FacesConverter("centroConverter")
public class centroConverter implements Converter {
public Object getAsObject(FacesContext fc, UIComponent uic, String value) {
if(value != null && value.trim().length() > 0) {
try {
CentroDAO centroDAO = new CentroDAO();
Integer id = Integer.parseInt(value);
Centro centro = centroDAO.getCentro(id);
return centro;
} catch(Exception e) {
System.out.println("Problema no centroConverter.!");
throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Erro de conversão", "Not a valid theme."));
}
}
else {
return null;
}
}
public String getAsString(FacesContext fc, UIComponent uic, Object object) {
if(object != null) {
Centro c = new Centro();
c = (Centro) object;
return ""+c.getIdCentro();
}
else {
return null;
}
}
}
Editalconverter.java
@FacesConverter("editalConverter")
public class editalConverter implements Converter {
public Object getAsObject(FacesContext fc, UIComponent uic, String value) {
if(value != null && value.trim().length() > 0) {
try {
EditalDAO editalDAO = new EditalDAO();
Integer id = Integer.parseInt(value);
Edital edital = editalDAO.getEdital(id);
return edital;
} catch(Exception e) {
System.out.println("Problema no editalConverter.!");
throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Erro de conversão", "Not a valid theme."));
}
}
else {
return null;
}
}
public String getAsString(FacesContext fc, UIComponent uic, Object object) {
if(object != null) {
Edital e = new Edital();
e = (Edital) object;
return ""+e.getIdEdital();
}
else {
return null;
}
}
}
Disciplinaconverter.java
@FacesConverter("disciplinaConverter")
public class disciplinaConverter implements Converter {
public Object getAsObject(FacesContext fc, UIComponent uic, String value) {
if(value != null && value.trim().length() > 0) {
try {
DisciplinaDAO disciplinaDAO = new DisciplinaDAO();
Integer id = Integer.parseInt(value);
Disciplina disciplina = disciplinaDAO.getDisciplina(id);
return disciplina;
} catch(Exception e) {
System.out.println("Problema no disciplinaConverter.!");
throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Erro de conversão", "Not a valid theme."));
}
}
else {
return null;
}
}
public String getAsString(FacesContext fc, UIComponent uic, Object object) {
if(object != null) {
Disciplina d = new Disciplina();
d = (Disciplina) object;
return ""+d.getIdDisciplina();
}
else {
return null;
}
}
}
The first method it calls, loads the list. But the second does not. I put a print just to test, but the method is not being called.
Have you tried instead of
valueChangeListener
use<p:ajax>
?– Luídne
put <p:ajax> that works
– Pedro Laini
@Luídne put the p ajax, but it doesn’t work the same way. He doesn’t call the method at all.
– João Neto
@Pedrolaini also.
– João Neto