File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes A-la Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "A-la "page" scope in JSF 1.2" Watch "A-la "page" scope in JSF 1.2" New topic

A-la "page" scope in JSF 1.2

Tim Wise

Joined: Jul 25, 2009
Posts: 15
Hi all,

I've "heard" that there is "page" scope for managed-beans in JSF 2.0. However, there is no such a thing in JSF 1.2. Currently I don't have any ability to upgrade, but would like to have similar functionality. So, the question is - what are the possible ways to store the data (ideally - any object) between several requests to the very same page? The need is to keep the same instance (or at least its complete state) between several requests - for example, currently I need to use some bean data in the action method, but the bean's state gets lost when a command button is clicked.

Many thanks for any ideas!

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

I missed hearing about Page Scope for JSF 2.0 - though that doesn't mean anything. However, Oracle's word on the subject is as follows:

You may notice that the "page" scope is not available in JSF. This is by design as managed beans are not tied specifically to pages whereas in traditional JSP, you would define the scope of a bean using a UseBean tag, and in this sense it makes sense to offer a page scope since the bean originated from the page.

In fact, if you want something to travel between requests, Page Scope is the exact opposite of what you need. Session Scope is designed for that.

Session Scope, however, sometimes is a little too permanent, however, so there are some specialized tagsets for things that are in between. The MyFaces Tomahawk features one such tag.

Do realize, however, that in cases where your data's life is extended over multiple pages that there are some caveats. If you're planning on keeping the data in the HTTP request/response (page) stream, the data must be serializable (including any embedded objects). It adds to the amount of data that has to be sent to/from the server on each page request, which can impact performance and response time. And, finally, any data you sent out to the client can potentially be exposed or modified for malicious purposes.

An IDE is no substitute for an Intelligent Developer.
Tim Wise

Joined: Jul 25, 2009
Posts: 15
Many thanks for the answer, Tim. Indeed session scope solves my problem of data transmission between pages. Finally I'm using an utility class to set\get\remove values to\from a session. I'm removing the data from a session right after the navigation is performed - in the getter or action methods of the target request-scope bean. Although it occurs that sometimes it is even better to keep some data in the session so as to enable correct navigation when user selects "Back" in a browser - in this case all the required data is still available. In fact I store only entity IDs in a session, so I'm not afraid to overload it.

I agree. Here's the link:
subject: A-la "page" scope in JSF 1.2
It's not a secret anymore!