JSF2 (Mojarra) View Scope Managed Bean 希望所有成员均可序列化
我正在尝试将会话范围的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我希望您已经解决了这个问题,但是对于登陆这里的其他人来说,他们不想使用会话范围并使用视图范围作为替代方案,这迫使您使用
serialized
实现,您可以在您不想可序列化
的属性旁边使用transient
关键字,如果您想调用服务或dao,这将非常有帮助。例子:
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 thetransient
keyword next to the properties that you don't want to makeserializable
, that would be very helpful if you want to call a service or dao.example:
参考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"