Naresh Bhatia wrote:
I have a very basic JSF question - how to save state in a page? I have
the following situation, Page A navigates to page B through a link. The
link has a request parameter in it, say productId=12. How do I make page
B remember that it was invoked with productId=12? I do not want to use
managed beans with session scope (trying to avoid session scope all
together). I can think of two ("traditional") approaches:

a) save the productId in a hidden form variable (h:inputHidden) making
it available when the page is posted back

b) add the productId as a request parameter on links on the page.

Are there other ways to do this - perhaps there is a preferred JSF way?

When you save "navigates through a link", if you mean an h:commandLink then there is no problem, as this works just like an h:commandButton. When the user clicks the commandLink a postback occurs to page A, which can configure request-scope beans then forward to page B. Because page B is in the same "request", it can see the data that page A set.

If you mean you want a normal html link (<a>) which passes parameters to a managed bean, then that's not trivial. Such links are not really supported by JSF; h:commandLink and h:commandButton are the "official" mechanisms for navigation in a JSF app. This link might be useful to you:
 http://wiki.apache.org/myfaces/InvokingJsfPagesWithStandardUrls


> Is javax.faces.STATE_SAVING_METHOD somehow related to this?

No. That determines how the "component tree state" is stored between requests, but that's a different thing from preserving the state of your model objects or managed beans.

Regards,

Simon

Reply via email to