【发布时间】:2011-10-26 23:22:11
【问题描述】:
我有一个 bean,它有一个名为 view() 的操作方法和一个 MyObject 类型的字段:
@ManagedBean
@ConversationScoped
public class MyBean implements Serializable{
private @Inject Conversation conversation; //has getter and setter
private MyObject object; //has getter and setter
... other fields follow
public String view(MyObject selectedObj){
conversation.begin();
return "success";
}
public String getSomeProperty(){
return object.getProperty();
}
...other methods follow
}
在 screen1.xhtml 上,我使用 primefaces p:dataTable 和 var="obj" 来输出带有 commandButton 的行,以查看用户单击的行的对象。每行的按钮如下所示。
<p:commandButton action="#{myBean.view(obj)}"
ajax="false" title="View Clone" image="ui-icon ui-icon-locked"/>
当用户单击其中一行中的命令按钮时,他们将被带到 page2.xhtml,其中显示有关 obj 的更多详细信息。这可以正常工作并显示详细信息。当我在 view(MyObject selectedObj) 操作方法中时,我立即调用 conversation.begin(),分配 this.obj = selectedObj,然后用户获取 page2.xhtml。
但是,当用户单击 page2 上的 commandButton 时,它应该重新显示与来自 page1 时发生的 view() 操作调用分配的 obj 不同的信息,因为范围已提升到对话。这没有发生。当作用域本应防止其丢失时,bean 中的 obj 字段为空。因此,当他们单击 page2 上的命令按钮时,当页面尝试解析 #{myBean.someProperty} 时,它会给出空指针异常。
我错过了什么?感谢您的帮助。
【问题讨论】:
-
我一定很擅长难倒人。我总是获得风滚草奖,因为没人能回答我的问题。太难了?
-
这可能会有所帮助 - stackoverflow.com/questions/5250311/…
标签: java jsf jakarta-ee jsf-2 seam-conversation