You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Yannick Le Teigner <ya...@laposte.net> on 2005/12/06 00:04:22 UTC
Drilldown type app. without session bean?
Hello,
I am trying to remove as many beans as possible from the session scope,
and I am facing some difficulties with drilldown pages.
Let's say I have a page listing some users in a dataTable. Clicking on a
user (commandLink), will bring you to a page where you can edit some
parameters about this user.
Up until today the selected user was placed in session scope.
Now, after changing the scope to request in faces-config, if I try to
put the user in the request map during the INVOKE_APPLICATION phase
(when the action of my commandLink is called), then another user (empty
this one) gets created during the RENDER_RESPONSE phase. The edit page
displays an empty user.
If I use the t:saveState component (putting one on the listing page, and
one on the edit page), the one on the listing page is created empty, and
it is re-created as empty on the edit page...
The code in the action of my commandLink is something along the lines:
FacesContext ctx = FacesContext.getCurrentInstance();
ctx.getExternalContext().getRequestMap().put("#{User}", new User(id));
Anyone knows the correct way of handling this?
Thank you,
Yannick
Re: Drilldown type app. without session bean?
Posted by Simon Kitching <sk...@obsidium.com>.
Yannick Le Teigner wrote:
> Hello,
>
> I am trying to remove as many beans as possible from the session scope,
> and I am facing some difficulties with drilldown pages.
>
> Let's say I have a page listing some users in a dataTable. Clicking on a
> user (commandLink), will bring you to a page where you can edit some
> parameters about this user.
>
> Up until today the selected user was placed in session scope.
>
> Now, after changing the scope to request in faces-config, if I try to
> put the user in the request map during the INVOKE_APPLICATION phase
> (when the action of my commandLink is called), then another user (empty
> this one) gets created during the RENDER_RESPONSE phase. The edit page
> displays an empty user.
>
> If I use the t:saveState component (putting one on the listing page, and
> one on the edit page), the one on the listing page is created empty, and
> it is re-created as empty on the edit page...
>
> The code in the action of my commandLink is something along the lines:
> FacesContext ctx = FacesContext.getCurrentInstance();
> ctx.getExternalContext().getRequestMap().put("#{User}", new User(id));
>
>
> Anyone knows the correct way of handling this?
<t:saveState> is the correct tag to use when you want to avoid
session-scoped managed beans.
I don't know why you have that command-link code; nothing like this is
necessary to use t:saveState. If you wish to preserve the state of an
entire managed bean, then do:
Master page:
<t:saveState value="#{myBackingBean}"/>
Detail page:
<t:saveState value="#{myBackingBean}"/>
On first visit to the master page, there is no saved state to restore,
so a default instance of that bean is created. When the page is
serialized after rendering, the bean's state is stored.
When either the master or detail page is visited thereafter, the saved
object is recreated from the saved state, and #{myBackingBean} is set to
be a reference to the restored object.
You can also save just specific fields of a bean via:
<t:saveState value="#{myBackingBean.someProperty}"/>
Regards,
Simon