开发者

How to create a view scoped bean in JSF 1.x?

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开发者_JAVA百科 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.


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.

<t:saveState value="#{bean}" />

It acts like the JSF 2.0 view scope.


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.


Take a look at MyFaces Orchestra.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜