I'm having problems accessing a method that stays in my ManagedBean, the idea is this: I have a page where I can check the records that are in the db from the "Browse" button and then the records appear, all in a good one however for each record I have the button next to "Remove" and "Edit", when I click the remove button it refreshes the page and does not even enter the method that I specified. Please help me in this, and to be a beginner with JSF technologies, Hibernate, etc ...
Listing Page
<h:form>
<h:commandButton value="Consultar Alunos"
action="#{controllerAluno.alunosCadastrados}" />
</h:form>
<br />
<p></p>
<h:form>
<p:dataTable var="item" value="#{controllerAluno.alunos}"
rendered="#{not empty controllerAluno.alunos}">
<p:column headerText="Cód. Aluno">
<center>
<h:outputText value="#{item.id}" />
</center>
</p:column>
<p:column headerText="Nome">
<center>
<h:outputText value="#{item.nome}" />
</center>
</p:column>
<p:column headerText="Data">
<center>
<h:outputText value="#{item.data_Nascimento}">
<f:convertDateTime pattern="dd, MMMM yyyy" locale="pt_BR"
timeZone="" />
</h:outputText>
</center>
</p:column>
<p:column headerText="Sexo">
<center>
<h:outputText value="#{item.sexo}" />
</center>
</p:column>
<p:column headerText="opções">
<center>
<h:commandButton value="Editar" />
||
<h:commandButton value="Remover"
action="#{controllerAluno.removerAluno(item)}" />
</center>
</p:column>
</p:dataTable>
</h:form>
<h:form>
<center>
<h3>
<h:commandLink value="Cadastrar novo Aluno"
action="paginaInicial?faces-redirect=true" />
</h3>
</center>
</h:form>
Methods Accessed on ManagedBean
Remove:
public void removerAluno(Aluno alunoSelecionado){
try {
EntityManagerFactory factory = Persistence.createEntityManagerFactory("conexaoDB");
EntityManager em = factory.createEntityManager();
EntityTransaction et = em.getTransaction();
System.out.println("Entrou");
et.begin();
Aluno a = em.find(Aluno.class, alunoSelecionado.getId());
em.remove(a);
System.out.println("Aluno: "+a.getNome()+" removido com sucesso!");
a =null;
alunoSelecionado = null;
em.close();
factory.close();
} catch (Exception e) {
e.printStackTrace();
}
}
Method that loads the ArrayList
@SuppressWarnings("unchecked")
public ArrayList<Aluno> alunosCadastrados(){
EntityManagerFactory factory = Persistence.createEntityManagerFactory("conexaoDB");
EntityManager em = factory.createEntityManager();
EntityTransaction et = em.getTransaction();
this.alunos = (ArrayList<Aluno>) em.createQuery("FROM " + Aluno.class.getName()).getResultList();
em.close();
factory.close();
return alunos;
}