Steve Atkinson
Steve Atkinson

Reputation: 1239

Emulating jsf 2.0 view scope in JSF 1.2 with Spring beans

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.

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

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.

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)

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.

Upvotes: 4

Views: 2243

Answers (1)

BalusC
BalusC

Reputation: 1108722

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.

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

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

Upvotes: 4

Related Questions