I have a simple CDI bean. The problem is that when I invoke method removeCustomer
from the JSF page, method getCustomers()
is executed before removeCustome
r instead the opposite way. First I thought that producer itself is the problem but I'm getting same behavior if I put the list inside the controller. When I get response page the row in the table is not removed ether it is removed from the database. When I refresh page once more I don't see the deleted row.
@Named
@RequestScoped
public class CustomersController {
@Inject
private CustomerService customerService;
@Produces()
@RequestScoped
@Named("customers")
public List<Customer> getCustomers() {
return customerService.findCustomers();
}
/**
* @param customerId
*/
public String removeCustomer(Long customerId) {
customerService.deleteCustomer(customerId);
return null;
}
}
<h:form id="customers-form">
<h:dataTable value="#{customers}" var="customer"
styleClass="table">
<h:column>
<f:facet name="header">#{msg['customer.name']}</f:facet>
#{customer.name}
</h:column>
<h:column>
<f:facet name="header">#{msg['customer.vat']}</f:facet>
#{customer.vat}
</h:column>
<h:column>
<a
href="#{facesContext.externalContext.requestContextPath}/customers/customer.xhtml?id=#{customer.id}">#{msg['global.edit']}</a>
</h:column>
<h:column>
<h:commandButton styleClass="btn btn-danger"
action="#{customersController.removeCustomer(customer.id)}"
value="#{msg['global.delete']}" aria-hidden="true">
<f:ajax render="@form"></f:ajax>
</h:commandButton>
</h:column>
</h:dataTable>
I'm using JBoss WildFly beta 1 but I'm guessing that it uses stable JSF 2.x version.