You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Matt Tyson <ma...@gmail.com> on 2006/12/13 22:28:38 UTC

resotring state

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?


Thanks,

Matt
-- 
View this message in context: http://www.nabble.com/resotring-state-tf2816777.html#a7861687
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: resotring state

Posted by Grant Smith <wo...@gmail.com>.
Hi Matt,

Just out of curiosity, why aren't you using Tomahawk's saveState component ?

Seems like you might be reinventing the wheel...

On 12/13/06, Matt Tyson <ma...@gmail.com> 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?
>
>
> Thanks,
>
> Matt
> --
> View this message in context:
> http://www.nabble.com/resotring-state-tf2816777.html#a7861687
> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>
>


-- 
Grant Smith

Re: resotring state

Posted by Matt Tyson <ma...@gmail.com>.
Simon,

I hear you.  I think the rationale behind the client-side is the heavy
server load.  Looks like one of those situations where there's no clear
winner -- highly dependant on the situation... ie, when does the memory
usage of server-side become more trouble than sending all that data on the
wire.

Fortunately, switching back to server-side is trivial -- at least for this
particular situation.

Matt


Simon Kitching-3 wrote:
> 
> Matt Tyson wrote:
>> Got it.  Here's the params I needed to send with the ajax request:
>> 
>> var clientTree = document.getElementById("jsf_tree_64").value;
>> 	var clientState = document.getElementById("jsf_state_64").value;
>> 	var viewId = document.getElementById("jsf_viewid").value;
>> 	
>> 	dojo.io.bind({
>> 		url: url,
>> 		load: function(type, data, evt){ treeTools.handleAjaxResponse(data) },
>> 		mimetype: "text/xml",
>> 		content: {  "ajaxTreeRequest": treeTools.getThisTreeId(clickedNode),
>> 		 			"id": id,
>> 		 			"name": name,
>> 		    		"provider": treeTools.getNodeDataProvider(clickedNode),
>> 		    		"jsf_tree_64": clientTree,
>> 		    		"jsf_state_64":clientState,
>> 		    		"jsf_viewid":viewId}
>> 	});
>> 
>> Only took a day.  Thanks for pointing me in the right direction Simon.
> 
> The only problem with this is that an AJAX request is supposed to be 
> "light", but the saved state trees can be quite large. In the case of 
> the app I'm currently working on, often around 100kb :-).
> 
> You might want to consider if client-side state is appropriate in your
> case.
> 
> Regards,
> 
> Simon
> 
> 

-- 
View this message in context: http://www.nabble.com/resotring-state-tf2816777.html#a7864156
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: resotring state

Posted by Simon Kitching <si...@rhe.co.nz>.
Matt Tyson wrote:
> Got it.  Here's the params I needed to send with the ajax request:
> 
> var clientTree = document.getElementById("jsf_tree_64").value;
> 	var clientState = document.getElementById("jsf_state_64").value;
> 	var viewId = document.getElementById("jsf_viewid").value;
> 	
> 	dojo.io.bind({
> 		url: url,
> 		load: function(type, data, evt){ treeTools.handleAjaxResponse(data) },
> 		mimetype: "text/xml",
> 		content: {  "ajaxTreeRequest": treeTools.getThisTreeId(clickedNode),
> 		 			"id": id,
> 		 			"name": name,
> 		    		"provider": treeTools.getNodeDataProvider(clickedNode),
> 		    		"jsf_tree_64": clientTree,
> 		    		"jsf_state_64":clientState,
> 		    		"jsf_viewid":viewId}
> 	});
> 
> Only took a day.  Thanks for pointing me in the right direction Simon.

The only problem with this is that an AJAX request is supposed to be 
"light", but the saved state trees can be quite large. In the case of 
the app I'm currently working on, often around 100kb :-).

You might want to consider if client-side state is appropriate in your case.

Regards,

Simon

Re: resotring state

Posted by Matt Tyson <ma...@gmail.com>.
Got it.  Here's the params I needed to send with the ajax request:

var clientTree = document.getElementById("jsf_tree_64").value;
	var clientState = document.getElementById("jsf_state_64").value;
	var viewId = document.getElementById("jsf_viewid").value;
	
	dojo.io.bind({
		url: url,
		load: function(type, data, evt){ treeTools.handleAjaxResponse(data) },
		mimetype: "text/xml",
		content: {  "ajaxTreeRequest": treeTools.getThisTreeId(clickedNode),
		 			"id": id,
		 			"name": name,
		    		"provider": treeTools.getNodeDataProvider(clickedNode),
		    		"jsf_tree_64": clientTree,
		    		"jsf_state_64":clientState,
		    		"jsf_viewid":viewId}
	});

Only took a day.  Thanks for pointing me in the right direction Simon.


Matt Tyson wrote:
> 
> Simon,
> 
> Here's where the problem arises.  This is an ajax request being handled in
> a phase listener.  I'm waiting till after the the restoreView phase, but
> with client-side, the request is 1) missing the state and 2) missing the
> viewRoot.  
> 
> So I can add the state information manually into the request, but I'm
> still not getting my state back, perhaps because of 2)?  
> 
> Any suggestions?
> 
> Thanks.
> 
> Matt
> 
> 
> Simon Kitching-3 wrote:
>> 
>> 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
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/resotring-state-tf2816777.html#a7863914
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: resotring state

Posted by Matt Tyson <ma...@gmail.com>.
Simon,

Here's where the problem arises.  This is an ajax request being handled in a
phase listener.  I'm waiting till after the the restoreView phase, but with
client-side, the request is 1) missing the state and 2) missing the
viewRoot.  

So I can add the state information manually into the request, but I'm still
not getting my state back, perhaps because of 2)?  

Any suggestions?

Thanks.

Matt


Simon Kitching-3 wrote:
> 
> 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
> 
> 

-- 
View this message in context: http://www.nabble.com/resotring-state-tf2816777.html#a7863028
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: resotring state

Posted by Simon Kitching <si...@rhe.co.nz>.
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