You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Session A Mwamufiya <sm...@andrew.cmu.edu> on 2007/08/07 15:53:39 UTC

reloading a tree at a certain level of expension

Hi,

Is there a way that when a s:tree is reloaded, it expends to a particular level of expansion?  I presume that I will save that expansion level in my session object, but I'm not sure how to get it or set the tree to it, or if it's even possible.

Thanks,
Session


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: reloading a tree at a certain level of expension

Posted by Oleg Mikheev <mi...@bigfoot.com>.
Session A Mwamufiya wrote:
> I'm relaunching this thread in case an s:tree expert may have missed it the first time around :).
>> Is there a way that when a s:tree is reloaded, it expends to a particular
>> level of expansion?  I presume that I will save that expansion level in
>> my session object, but I'm not sure how to get it or set the tree to it,
>> or if it's even possible.

You don't need to be an expert to see that s:tree doesn't have support
for auto expanding trees. You will have to do it programaticaly:
http://dojotoolkit.org/pipermail/dojo-interest/2006-June/011325.html

Oleg

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: reloading a tree at a certain level of expension

Posted by Manu Mahajan <ma...@comprotechnologies.com>.
Hi Session

I don't know if it can be done only via the struts tags but I was able to
achieve this by using some dojo javascript code in my jsp. 

Here are some code snippets that might solve your problem

<html>
<head>
.
.
.
  <s:head theme="ajax" debug="true"/>
  
  //The following extensions are required to save or restore state of a tree
  dojo.require("dojo.widget.TreeLoadingController");
  dojo.require("dojo.widget.TreeControllerExtension");
  
  dojo.addOnLoad(function() {
    dojo.lang.mixin(dojo.widget.byId('treeController'),
dojo.widget.TreeControllerExtension.prototype);
    //The following code will make sure that the saveExpandedIndices
function is called everytime a node 
    //is collapsed or expanded
    dojo.event.topic.subscribe("contentTree/expand",saveExpandedIndices);
    dojo.event.topic.subscribe("contentTree/collapse",saveExpandedIndices);

    
  });
  
  //The following function saves the state of the tree
  function saveExpandedIndices() {
    // You can save this object as tree persistent state
    indices = dojo.widget.byId('treeController').saveExpandedIndices(
      dojo.widget.byId('contentTree')
    );
    /*
    * "indices" is a javascript object which is nothing but a
multi-dimension arrays containing indices of all expanded nodes
    * I am saving this object inside a cookie. You can have a different
implementation...
    * I am using json.js to convert the object into a string
    * and then a custom function called storeCookie which stores the string
in a cookie
    */
    storeCookie("categoryTreeState",indices.toJSONString(),1);
  }
.
.
.
  //The following function restores the state of the tree. This can probably
be called body-onload
  //You will have to pass it the stored indices object though
  function restoreExpandedIndices(indices) {
      dojo.widget.byId('treeController').restoreExpandedIndices(
      dojo.widget.byId('contentTree'), indices
    );
  }
.
.
.
</head>
<body>
.
.
.
<div dojoType="TreeLoadingController" widgetId="treeController"
RPCUrl="local"></div>
<s:tree id="contentTree" 
    name="contentTree"
    theme = "ajax"
        rootNode="%{category}"
        childCollectionProperty="categoryList"
        nodeIdProperty="identifierString"
        nodeTitleProperty="name">
</s:tree>
.
.
.
</body>

Hope this helps.

Manu

-----Original Message-----
From: Session A Mwamufiya [mailto:smwamufi@andrew.cmu.edu] 
Sent: Wednesday, September 05, 2007 10:34 PM
To: Struts Users Mailing List
Cc: Struts Users Mailing List
Subject: Re: reloading a tree at a certain level of expension

Anyone knows whether this feature has been added in yet?

> Session A Mwamufiya wrote:
>> I'm relaunching this thread in case an s:tree expert may have missed it
>> the first time around :).
>> 
>>> Is there a way that when a s:tree is reloaded, it expends to a
>>> particular level of expansion?  I presume that I will save that
>>> expansion level in my session object, but I'm not sure how to get it
>>> or set the tree to it, or if it's even possible.
> 
> 
> Looking into TreeSelector API I found a selectedNode parameter - will it
> do the job? Feel free to ask Struts2 developers to include selectedNode
> parameter into s:tree tag if is does what you expect (and if it's not
> included there yet - sometimes S2 code changes faster than its
> documentation).
> 
> Oleg
> 
> --------------------------------------------------------------------- To
> unsubscribe, e-mail: user-unsubscribe@struts.apache.org For additional
> commands, e-mail: user-help@struts.apache.org
> 
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: reloading a tree at a certain level of expension

Posted by Session A Mwamufiya <sm...@andrew.cmu.edu>.
Anyone knows whether this feature has been added in yet?

> Session A Mwamufiya wrote:
>> I'm relaunching this thread in case an s:tree expert may have missed it
>> the first time around :).
>> 
>>> Is there a way that when a s:tree is reloaded, it expends to a
>>> particular level of expansion?  I presume that I will save that
>>> expansion level in my session object, but I'm not sure how to get it
>>> or set the tree to it, or if it's even possible.
> 
> 
> Looking into TreeSelector API I found a selectedNode parameter - will it
> do the job? Feel free to ask Struts2 developers to include selectedNode
> parameter into s:tree tag if is does what you expect (and if it's not
> included there yet - sometimes S2 code changes faster than its
> documentation).
> 
> Oleg
> 
> --------------------------------------------------------------------- To
> unsubscribe, e-mail: user-unsubscribe@struts.apache.org For additional
> commands, e-mail: user-help@struts.apache.org
> 
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: reloading a tree at a certain level of expension

Posted by Oleg Mikheev <mi...@bigfoot.com>.
Session A Mwamufiya wrote:
> I'm relaunching this thread in case an s:tree expert may have missed it the first time around :).
> 
>> Is there a way that when a s:tree is reloaded, it expends to a particular
>> level of expansion?  I presume that I will save that expansion level in
>> my session object, but I'm not sure how to get it or set the tree to it,
>> or if it's even possible.


Looking into TreeSelector API I found a selectedNode parameter -
will it do the job?
Feel free to ask Struts2 developers to include selectedNode parameter
into s:tree tag if is does what you expect (and if it's not included
there yet - sometimes S2 code changes faster than its documentation).

Oleg

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: reloading a tree at a certain level of expension

Posted by Session A Mwamufiya <sm...@andrew.cmu.edu>.
I'm relaunching this thread in case an s:tree expert may have missed it the first time around :).

Thanks for any help,
Session


> Hi,
> 
> Is there a way that when a s:tree is reloaded, it expends to a particular
> level of expansion?  I presume that I will save that expansion level in
> my session object, but I'm not sure how to get it or set the tree to it,
> or if it's even possible.
> 
> Thanks, Session
> 
> 
> --------------------------------------------------------------------- To
> unsubscribe, e-mail: user-unsubscribe@struts.apache.org For additional
> commands, e-mail: user-help@struts.apache.org
> 
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org