I have a dialog that is supose to add a object in my arraylist and data base, but my actionListener just don't call my function! I tried to put some prints and no one is called inside my function, but everthing seens to be fine. Anyone can find the problem?
My dialog:
<p:dialog header="Novo Aluno" widgetVar="novoDialog" modal="true"
resizable="false">
<h:form>
<p:outputPanel>
<p:panelGrid columns="2">
<h:outputText value="Nome: " />
<p:inputText value="#{alunosView.alunoNovo.nome}" />
</p:panelGrid>
<p:panelGrid columns="1">
<p:selectOneMenu value="#{alunosView.alunoNovo.turma}">
<f:selectItems value="#{alunosView.turmas}" var="turma"
itemLabel="#{turma.curso} - #{turma.ano}º ano" />
</p:selectOneMenu>
</p:panelGrid>
<p:panelGrid columns="2">
<p:commandButton value="Adicionar" update=":form:alunos"
actionListener="#{alunosView.adicionarAluno}"
oncomplete="PF('novoDialog').hide();" />
<p:commandButton value="Cancelar"
oncomplete="PF('novoDialog').hide();" />
</p:panelGrid>
</p:outputPanel>
</h:form>
</p:dialog>
My bean:
@ManagedBean
@ViewScoped
public class AlunosView {
ArrayList<Aluno> alunos;
ArrayList<Turma> turmas;
Aluno alunoSelecionado;
Aluno alunoNovo;
ClassDAO<Aluno> alunoDao;
ClassDAO<Turma> turmaDao;
@PostConstruct
public void init(){
alunoDao = new ClassDAO<>(Aluno.class);
turmaDao = new ClassDAO<>(Turma.class);
alunos = alunoDao.getAll();
turmas = turmaDao.getAll();
alunoSelecionado = new Aluno();
alunoNovo = new Aluno();
}
public void adicionarAluno(){
System.out.println("asdhaisdisdhisdaisdahiasdhsad dkgsad ksa gdlasds");
alunoDao.save(alunoNovo);
alunos = alunoDao.getAll();
}
public void deletarAluno(){
alunoDao.remove(alunoSelecionado.getId());
alunos = alunoDao.getAll();
}
public void salvarAluno(){
alunoDao.save(alunoSelecionado);
alunos = alunoDao.getAll();
}
public ArrayList<Aluno> getAlunos() {
return alunos;
}
public void setAlunos(ArrayList<Aluno> alunos) {
this.alunos = alunos;
}
public ArrayList<Turma> getTurmas() {
return turmas;
}
public void setTurmas(ArrayList<Turma> turmas) {
this.turmas = turmas;
}
public Aluno getAlunoSelecionado() {
return alunoSelecionado;
}
public void setAlunoSelecionado(Aluno alunoSelecionado) {
this.alunoSelecionado = alunoSelecionado;
}
public Aluno getAlunoNovo() {
return alunoNovo;
}
public void setAlunoNovo(Aluno alunoNovo) {
this.alunoNovo = alunoNovo;
}
}
The most stranger thing is that I have other page almost equal to this one and that page and that bean works fine! The code in the post construct method works fine too. Anyone help me?