0

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?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Gustavo Mendonça
  • 1,925
  • 3
  • 15
  • 26
  • If the pages are _"almost equal "_ then I'd try to find the differences! – Kukeltje Sep 02 '16 at 06:48
  • Just to know, all the solutions mentioned in the post that suppose to have a solution, failed. So, I still have the problem and someone closed my post. I'll make the page with other components, place the button in the page itself instead in a dialog. – Gustavo Mendonça Sep 06 '16 at 00:54
  • Please make your code a [mcve]. Most likely the duplicate does contain the solution though – Kukeltje Sep 06 '16 at 07:03

0 Answers0