I am doing a mini jsf project that is created by using jpa. I have listed costumers and I can remove them one by one, but if I want to remove selected costumers I cannot do it.
This part is from Costumer class
@Transient
private Boolean selection = false;
And this part is from CostumerBean
Costumer costumer = new Costumer();
private List<Costumer> costumerList = new ArrayList<>();
//(getters and setters)
public void removeSelected() {
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
for (Costumer cos : costumerList) {
if (cos.getSelection()) {
em.remove(em.contains(costumer) ? customer : em.merge(costumer));
}
}
em.getTransaction().commit();
musteri = new Musteri();
}
And finally here is the xhtml page :
<h:form id="firstForm">
<p:commandButton action="#{customerBean.removeSelection}" value="Remove"
update="customerForm">
</p:commandButton>
</h:form id="firstForm">
<h:form id="customerForm">
<p:dataTable value="#{customerBean.customerList}" var="cst"
id="cstTable">
<p:column>
<f:facet name="header">Select</f:facet>
<p:selectBooleanCheckbox value="#{cst.selection}" />
</p:column>
<p:column>
<f:facet name="header">Name</f:facet>
#{cst.name}
</p:column>
</h:form id="customerForm">
I reckon actual problem is I cannot make selection field in Costumer.java true. No action I see.?