I'm creating a page that has to have 3 SelectOneMenu
of primefaces.
In the first one I will load a center (of the university), the second will carry a edital and the third would load the disciplines of this edital.
The first SelectOneMenu
works, when change of option it loads only the edicts of that option. But when I change the option of the second SelectOneMenu
it no longer calls the method. Why is not he calling the method? What is wrong? Here are 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>
inscriptionBean.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;
}
}
}
DisciplineConverter.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.