如何在 JSF 1.x 中创建视图作用域 bean?
我的网页中有 2 个链接,其中一品脱链接到 appserver/?dept=1,链接二是 appserver/?dept=2。然后我有一个 JSF 阶段侦听器,在那里我可以获取后端 bean 并将 dept1 或 dept2 设置为 bean 参数,以便呈现不同的部门内容。如果用户从上面的网页启动 2 个窗口,则 dept1 窗口的内容可以转到 dept2 窗口。一切都乱了。 (注意,如果您从桌面快捷方式启动浏览器,输入上面的链接,没问题,因为将创建 2 个会话,创建 2 个不同的后端 bean 实例)。
关键原因是JSF将后端bean存储在会话中,因此来自同一父窗口的2个窗口共享相同的会话id(cookie),然后使用相同的后端bean类实例。在渲染结果时,结果可以转到任一窗口。
如何避免这种窗口交叉内容的情况?这似乎是一个基本的网络应用程序问题,很久以前就应该解决。或者我可能做错事了。
我尝试了seam转换,没有帮助,JSF2.0有视图范围,CDO。剂量有帮助吗?由于各种原因,我们还不能迁移到JSF2.0。我使用的是JAVA6、Tomcat6.20、Icefaces。任何帮助都是适当的。
I have 2 links in a web page, link one pint to appserver/?dept=1, link two is appserver/?dept=2. Then I have a JSF phase listener, in there, I can get the back end bean and set dept1 or dept2 as the bean parameter, in order to render different department contents. If user starts 2 windows from above web page, the contents of dept1 window can go to dept2 window. All messed up. (Note, if you start browser from desk top short cut, type in above links, no problem, since 2 session will be created, 2 different back end bean instances crated).
The key reason is JSF store back bean in the session, thus 2 windows which from the same parent window shared the same session id (cookie), then used the same back end bean class instance. At render result time, the result can go to either window.
How can I avoid this window cross contents situation? This seems a fundamental web app problem that should be resolve long time ago. Or I might doing things really wrong.
I tried seam conversion, no help, JSF2.0 has view scope, CDO. dose it can help ? We can not move to JSF2.0 yet due to various reason. I am using JAVA6, Tomcat6.20, Icefaces. Any help is appropriated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 JSF 1.x 中,最好的选择是 Tomahawk
。只需将其放在由同一页面触发的后续请求中要保留指定请求作用域 bean 的页面中,无论浏览器选项卡/窗口如何。它的行为类似于 JSF 2.0 视图范围。
In JSF 1.x, your best bet is Tomahawk's
<t:saveState>
. Just put it in the page where the specified request scoped bean is to be retained in the subsequent request which is fired by the very same page, regardless of the browser tab/window.It acts like the JSF 2.0 view scope.
您的问题可以通过使用seam对话轻松解决,您可以查看seam包附带的示例。您需要将支持 bean 范围从会话更改为对话并使用页面参数。 Seam in Action 书中还用非常好的、简短的例子解释了这个用例。
your problem easily can be solved by using seam conversations, you can look at the examples come with seam package. you need to change your backing bean scope to conversation from session and use page parameters. also seam in action book explains this use case with very nice and brief examples.
看看 MyFaces Orchestra。
Take a look at MyFaces Orchestra.