【发布时间】:2011-07-29 16:55:09
【问题描述】:
我正在从 RichFaces 3.3.3 迁移到 4.0,遇到了一个不知道如何解决的问题。
到目前为止,我已经使用 RichFaces 的@KeepAlive 注解来实现带有 bean 的 View 范围,但是新版本 4 到目前为止还没有这样的功能(据我所知)。所以我认为 @ViewScoped 注释将是自然(且快速)的替代品,但它不起作用。 这是给我带来麻烦的相关代码。它呈现一个包含客户及其姓名的表格作为链接,因此当单击名称时,它会弹出一个弹出窗口来编辑数据。它在 v3.3.3 中与 @KeepAlive 一起使用,但在 v4 中与 @ViewScoped 不兼容(不会调用弹出窗口)。
页面:
<h:form prependId="false">
<rich:dataTable id="table" value="#{myBean.customers}" var="customer">
<!--...headers...-->
<h:column>
<a4j:commandLink action="#{myBean.selectCustomer}"
oncomplete="#{rich:component('popup_customer_editor')}.show();" render="form_customer_editor">
${customer.name}
<f:setPropertyActionListener value="#{customer}" target="#{myBean.selectedCustomer}"/>
</a4j:commandLink>
</h:column>
<h:column>${customer.address}</h:column>
</rich:dataTable>
</h:form>
<rich:popupPanel id="popup_customer_editor>
<h:form id="form_customer_editor">
<!--...form fields...-->
</h:form>
</rich:popupPanel>
豆子:
@ManagedBean
@ViewScoped //It was @KeepAlive before
public class MyBean implements Serializable
{
private String name;
private String address;
private Customer selectedCustomer; //POJO class
//getters and setters
...
public String selectCustomer()
{
name = selectedCustomer.getName();
address = selectedCustomer.getAddress();
return null;
}
}
任何帮助将不胜感激
【问题讨论】: