JSF2 (Mojarra) View Scope Managed Bean 希望所有成员均可序列化

发布于 2024-10-28 04:40:48 字数 466 浏览 2 评论 0原文

我正在尝试将会话范围的 JSF 托管 bean 转换为视图范围。但是,当我尝试访问此 bean 的 xhtml 页面时,出现以下错误:

java.io.NotSerializedException: foo.bar.SomeDaoClass

我有一个辅助 DAO 的成员,我用它来委派与持久性相关的任务豆。如果我让这个 DAO 类实现 Serialized,那么其他 UIComponent 引用就会开始导致相同的错误!

主要用例是我有一个链接,单击该链接我会打开一个 jquery lightbox 弹出窗口,显示由会话 bean 支持的 xhtml 页面。当用户单击弹出表单上的提交按钮时,我以编程方式删除会话 bean。问题是,如果用户单击弹出窗口本身的关闭按钮,然后单击指向另一个 id 的另一个链接,则会显示相同的值(在会话范围内)!

我想在弹出窗口中查看此表单时使用视图范围来保留值,并且当用户单击弹出窗口的关闭按钮时,这些值可能会被丢弃。

I am trying to convert a session scoped JSF managed bean to view scoped. However, when I try to access the xhtml page for this bean, then i get the following error:

java.io.NotSerializableException: foo.bar.SomeDaoClass

I have a member of a helper DAO that I use to delegate persistence related tasks within the bean. If I make this DAO class implement Serializable then other UIComponent references start causing the same errors!

The main use case is that I have a link on the click of which I open a jquery lightbox pop-up showing the xhtml page which is backed by a session bean. When the user clicks the submit button on the pop-up form, I remove the session bean programatically. The problem is if the user clicks the close button of the pop-up itself, and clicks on another link pointing to another id, then the same values are shown (being session scoped)!

I would like to use the view scope to preserve values while viewing this form in a pop-up and when the user clicks the close button of the pop-up, the values may be discarded.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

明媚如初 2024-11-04 04:40:48

我希望您已经解决了这个问题,但是对于登陆这里的其他人来说,他们不想使用会话范围并使用视图范围作为替代方案,这迫使您使用 serialized 实现,您可以在您不想可序列化的属性旁边使用transient关键字,如果您想调用服务或dao,这将非常有帮助。

例子:

@ManagedBean(name="addressTableBeanExample4")
@ViewScoped
public class ExampleBean4 implements Serializable {

    private static final long serialVersionUID = 1L;

    // non serialazable class
    private transient List<Customer> data = new ArrayList<Customer>();

    private Customer selected;
}

I hope you've already resolved this problem, but for other people landing here, who don't want to use session scope and uses view scope as alternative, which force you to use serializable implementation, you can use the transient keyword next to the properties that you don't want to make serializable, that would be very helpful if you want to call a service or dao.

example:

@ManagedBean(name="addressTableBeanExample4")
@ViewScoped
public class ExampleBean4 implements Serializable {

    private static final long serialVersionUID = 1L;

    // non serialazable class
    private transient List<Customer> data = new ArrayList<Customer>();

    private Customer selected;
}
猫弦 2024-11-04 04:40:48

参考Balusc博客
http://balusc.blogspot.com/2010/06 /benefits-and-pitfalls-of-viewscoped.html

“简而言之:当任何 UIComponent 使用绑定属性绑定到 bean 时,@ViewScoped 就会中断”

Referring to Balusc blog
http://balusc.blogspot.com/2010/06/benefits-and-pitfalls-of-viewscoped.html

"In a nutshell: the @ViewScoped breaks when any UIComponent is bound to the bean using binding attribute"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文