Hi Simon,

Thanks for a quick response.

When I said "navigates through a link", I had first tried h:commandLink.
However, as you mention below, it was posting back to page A and causing
an unnecessary database read (I was doing lazy loading in my bean and
since this was a brand new bean, it was hitting the DB for no good
reason). Therefore, I switched to a raw <a> tag. Surprisingly enough, I
was able to make it work painlessly. Here's my code:

<a
href="#{ctx}/pages/ShowForum.jsf?forumId=#{forum.id}">#{forum.title}</a>

Note that I am using Facelets as my view handler. Of course, I don't
like this approach too much, because now my navigaion code is sitting in
the page instead of faces.config. These are some of the reasons why
asked my original question about the best ways to save state.

Naresh

-----Original Message-----
From: Simon Kitching [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, November 29, 2006 2:23 PM
To: MyFaces Discussion
Subject: Re: Saving state in page

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