使用Spring Bean在JSF 1.2中模拟jsf 2.0视图范围 [英] Emulating jsf 2.0 view scope in JSF 1.2 with Spring beans

查看:62
本文介绍了使用Spring Bean在JSF 1.2中模拟jsf 2.0视图范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JSF 1.2进行一个项目,该项目在WAS 7之上将portlet部署到WebSphere Portal Server 6.1.由于各种合同/政治原因,我们对JSF 1.2感到困惑.

I'm working on a project using JSF 1.2 deploying a portlet to WebSphere Portal Server 6.1 on top of WAS 7. For various contractual/political reasons, we're stuck with JSF 1.2.

但是.我们在整个应用程序中都使用Spring Bean,以便获取AoP日志记录.

However. we are using Spring beans throughout our application in order to get AoP logging.

我们不能使用JSF 2.0,这有点令人讨厌.特别是,视图范围将是我们应用程序的理想选择.这将是一个使用率很高的站点,并且将所有页面bean都保留在会话范围内是浪费的,我相信稍后会引起非功能测试团队的关注.

It is somewhat annoying that we can't use JSF 2.0. In particular, view scope would be ideal for our app. It will be a high usage site and keeping all the page beans in session scope is wasteful and I'm sure will cause raised eyebrows from our non-functional testing team later on.

在我看来,我可以通过使用Spring的自定义范围和一个自定义JSF组件来模拟View Scope,该JSF组件仅维护由Spring范围设置的活动bean的映射,并将此组件附加到我们的页面上.与可以在此映射中找到bean的自定义变量解析器一起,我们应该能够模拟视图范围

It occurred to me that I could emulate View Scope by using Spring's custom scope and a custom JSF component that simply maintains a map of active beans set by the Spring scope and attaching this component on our pages. Together with a custom variable resolver that can find beans in this map, we should be able to emulate view scope

(我们的旅程只有四页,但是每一页都有对同一页的一些回发)

(Our journey is only four pages, but each page has a few postbacks to the same page)

这种方法听起来如何?我想确保在将其呈现给我的项目同事并冲刺并开始撕开我们已经编写的Bean代码之前,我不会以某种方式射击自己.

How does this approach sound? I want to be sure I'm not somehow shooting myself in the foot before I present this to my project colleagues and dash off and start ripping apart the bean code we've already written.

推荐答案

不确定Spring,但对于JSF 1.2托管bean, Tomahawk的 <t:saveState> 是使JSF 1.2请求范围内的bean行为(几乎)与JSF 2.0视图范围内的bean完全一样的方式.几乎是因为在JSF 2.x中销毁视图和保存状态效率更高.但是效果最终是相同的.

Not sure about Spring, but for JSF 1.2 managed beans, the Tomahawk's <t:saveState> was the way to let a JSF 1.2 request scoped bean behave (almost) exactly like JSF 2.0 view scoped bean. Almost, because the destroying of the view and the state saving is a bit more efficient in JSF 2.x. But the effect is ultimately the same.

您需要做的就是在视图中的其他位置通过该标记引用Bean:

All you need to do is referencing the bean by that tag elsewhere in the view:

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

这篇关于使用Spring Bean在JSF 1.2中模拟jsf 2.0视图范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆