You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Marcel Brückner <m....@amplify-media.de> on 2008/07/06 22:31:20 UTC

SaveState and getViewRoot errors

Hi everyone,

I try this mailing-list since I didn¹t get any sufficient answer anywhere
else:
(Versions: MyFaces API/Impl 1.15 and Tomahawk 1.1.6 with Tomcat 5.5)

I use request scope beans a lot as backing beans for JSF/MyFaces.
With my current approach I see a lot of ³sometimes errors² in the following
situation:

----
1. XHTML page using facelets and <t:saveState> where the current backing
bean (MyBean) of the page is stored (<t:saveState value="#{MyBean}" />
2. MyBean trying to access the UIViewRoot with the help of the FacesContext
in the constructor.
----

Now whenever I leave the page where the saveState is used, I get an "null"
result when requesting the UIViewRoot from the MyBean constructor.
I use the UIViewRoot to access a ResourceBundle to translate labels which
get loaded dynamically inside several page elements (OneSelectMenus and
SelectButtons). The error occurs if I try to saveState a backing bean which
is currently used by the active jsf page, which made me think :-/.

Any ideas? I already have the feeling the accessing the UIViewRoot in the
constructor is evil, but could not verify nor change this.

Marcello.


Re: SaveState and getViewRoot errors

Posted by Martin Marinschek <ma...@gmail.com>.
Hi Marcello,

you are getting at the view-root in your m-bean constructor like this

FacesContext.getCurrentInstance().getViewRoot();

?

This will return null in the cases where the view has not been
created/set yet. The question is now when your constructor is called -
you can easily debug your code to find out, put a break-point in the
constructor. I would imagine you are in the restore-view-phase, and
the view has not yet been created or set into the FacesContext.

Generally, I don't see why you do this in the constructor - you should
not initialize anything in your constructor really.

regards,

Martin