Matt Tyson wrote:
Hello,
This works using server-side state saving:
UIViewRoot viewRoot =
context.getApplication().getViewHandler().restoreView(context, viewId);
And then I can get the component I'm interested in. The viewRoot has no
children if its client-side state saving. Do I need to manually restore the
state? If so, how do I do that - I've got the value from the "jsf_tree_64"
field, but how do you convert it to a State object to give to the
viewRoot.restoreState() method?
By coincidence, I've been going through the relevant MyFaces code today
for an unrelated reason.
I would have thought the above code would work fine.
Application.getViewHandler should return an instance of
JspViewHandlerImpl. This will then delegate to JspStateHandlerImpl which
will check whether client or server state is used:
protected UIViewRoot restoreTreeStructure(FacesContext facesContext,
String viewId,
String renderKitId)
{
UIViewRoot uiViewRoot;
if (isSavingStateInClient(facesContext))
{
//reconstruct tree structure from request
RenderKit rk = getRenderKitFactory().getRenderKit(
facesContext, renderKitId);
ResponseStateManager responseStateManager =
rk.getResponseStateManager();
Object treeStructure =
responseStateManager.getTreeStructureToRestore(
facesContext, viewId);
....
}
ResponseStateManager should be an instance of HtmlResponseStateManager:
public Object getTreeStructureToRestore(
FacesContext facescontext, String viewId)
{
Map reqParamMap =
facescontext.getExternalContext().
getRequestParameterMap();
Object param = reqParamMap.get(VIEWID_PARAM);
if (param == null || !param.equals(viewId))
{
//no saved state or state of different viewId
return null;
}
param = reqParamMap.get(TREE_PARAM);
.....
So the tree structure required should be fetched from request property
VIEWID_PARAM or TREE_PARAM automatically when restoreView is called on a
JspStateHandlerImpl.
Regards,
Simon