【发布时间】:2013-12-02 08:28:37
【问题描述】:
我有一个简单的 CDI bean。问题是当我从 JSF 页面调用方法 removeCustomer 时,方法 getCustomers() 在 removeCustomer 之前执行,而不是相反的方式。首先,我认为生产者本身就是问题,但是如果我将列表放在控制器中,我会得到相同的行为。当我得到响应页面时,表中的行不会被删除,它会从数据库中删除。当我再次刷新页面时,我看不到已删除的行。
@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>
我正在使用 JBoss WildFly beta 1,但我猜它使用的是稳定的 JSF 2.x 版本。
【问题讨论】: