You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Adam <ad...@softfab.com> on 2006/07/31 10:59:30 UTC

Tree2 - a new node & scroll to?

Dear All,

we are happily using tree2 & the problem I have is to do with the scrolling.

Is there anyway to tell the scrooling mechanism to scroll to a given node?

i.e. we have a tree which is sufficiently large that it needs a scroll 
bar etc. When we add a new node, it is added to the end of the tree in 
some applications & in a sorted position in others (e.g. the nodes are 
alphabetically sorted).his means that when a user clicks to add a new 
node, he has to scroll down to the end of what might be a large tree 
every time which can get to be a pain for those inserting data.

I add a node as follows:

		Node XPNode = deb.addChildN();
		String path = dtb.getpathToRoot(XPNode);
		dtb.tree.expandPath(dtb.tree.getPathInformation(path));

& the node happily expands etc but....that in no way interacts with the 
scrolling. i..e the node is expanded but it's still off the page & 
requires scrolling to get to it.

So how do I (can I?) set the focus to the node added as above such that 
the scrolling mechanism takes the user to that node?

TIA


Adam


Re: Tree2 - a new node & scroll to?

Posted by Adam <ad...@softfab.com>.
Andrew Robinson wrote:
> There are javascript methods to scroll to a given node in the DOM tree
> if you need to scroll the whole document. If you are in an inner div
> you will want to use scrollTop and scrollHeight to determine & set the
> scroll position of the div. Just give an element in your node a static
> ID (forceId from tomahawk) so that you can find it using javascript.
> 
> Just google the web on scrolling if you are not up to speed on these
> javascript methods.
> 

Thanks.

As mentioned in my other reply, it is something which I will do in 
JScript is I have to but should be available from Java as otherwise 
you're mixing code from all over the place (some in your backing beans, 
some in your web page, some JScript some Java etc).

I'd like to lodge a request to see a "setFocus" method which should take 
a path much like expand & it should expand the tree to that node & then 
set the focus to that node such that the std Jscript scroller used by 
Tree2 can find & position itself (much like when you click on a node & 
the page is refreshed & then t resets the position to node you have 
clicked on).


Something like:

String path = dtb.getpathToRoot(XPNode);
dtb.tree.setFocus(dtb.tree.getPathInformation(path));

Adam


> On 7/31/06, Adam <ad...@softfab.com> wrote:
>> Dear All,
>>
>> we are happily using tree2 & the problem I have is to do with the 
>> scrolling.
>>
>> Is there anyway to tell the scrooling mechanism to scroll to a given 
>> node?
>>
>> i.e. we have a tree which is sufficiently large that it needs a scroll
>> bar etc. When we add a new node, it is added to the end of the tree in
>> some applications & in a sorted position in others (e.g. the nodes are
>> alphabetically sorted).his means that when a user clicks to add a new
>> node, he has to scroll down to the end of what might be a large tree
>> every time which can get to be a pain for those inserting data.
>>
>> I add a node as follows:
>>
>>                 Node XPNode = deb.addChildN();
>>                 String path = dtb.getpathToRoot(XPNode);
>>                 dtb.tree.expandPath(dtb.tree.getPathInformation(path));
>>
>> & the node happily expands etc but....that in no way interacts with the
>> scrolling. i..e the node is expanded but it's still off the page &
>> requires scrolling to get to it.
>>
>> So how do I (can I?) set the focus to the node added as above such that
>> the scrolling mechanism takes the user to that node?
>>
>> TIA
>>
>>
>> Adam
>>
>>
> 


Re: Tree2 - a new node & scroll to?

Posted by Andrew Robinson <an...@gmail.com>.
There are javascript methods to scroll to a given node in the DOM tree
if you need to scroll the whole document. If you are in an inner div
you will want to use scrollTop and scrollHeight to determine & set the
scroll position of the div. Just give an element in your node a static
ID (forceId from tomahawk) so that you can find it using javascript.

Just google the web on scrolling if you are not up to speed on these
javascript methods.

On 7/31/06, Adam <ad...@softfab.com> wrote:
> Dear All,
>
> we are happily using tree2 & the problem I have is to do with the scrolling.
>
> Is there anyway to tell the scrooling mechanism to scroll to a given node?
>
> i.e. we have a tree which is sufficiently large that it needs a scroll
> bar etc. When we add a new node, it is added to the end of the tree in
> some applications & in a sorted position in others (e.g. the nodes are
> alphabetically sorted).his means that when a user clicks to add a new
> node, he has to scroll down to the end of what might be a large tree
> every time which can get to be a pain for those inserting data.
>
> I add a node as follows:
>
>                 Node XPNode = deb.addChildN();
>                 String path = dtb.getpathToRoot(XPNode);
>                 dtb.tree.expandPath(dtb.tree.getPathInformation(path));
>
> & the node happily expands etc but....that in no way interacts with the
> scrolling. i..e the node is expanded but it's still off the page &
> requires scrolling to get to it.
>
> So how do I (can I?) set the focus to the node added as above such that
> the scrolling mechanism takes the user to that node?
>
> TIA
>
>
> Adam
>
>

Re: Tree2 - a new node & scroll to?

Posted by Adam <ad...@softfab.com>.
Sean Schofield wrote:
> I haven't tried using anchors in JSF but presumably that would be the
> solution.  Since the nodes are all JSF objects if you can find a way
> to add a '#foo' to the URL then you could scroll to the specific
> location.  I don't believe there is a way to do this in the JSF spec
> but its probably something that should be supported.  Your use case is
> a pretty common one (I've experienced this before.)
> 
> There is a post on the Sun forum that deals with the issue[1].  Maybe
> this is a case for a new attribute for commandLink/commandButton?
> 
> Sean
> 
> [1] http://forum.java.sun.com/thread.jspa?threadID=490215&messageID=2301780
> 
> 

Thanks. It does appear to be a fairly std thing for a tree to do. Maybe 
some sort of "setFocus" method on the tree where like expand you provide 
a path? In fact you could combine expand and setFocus into one i.e. 
calling setFocus should expand that node/path & then set the focus onto 
that node.

e.g.:

String path = dtb.getpathToRoot(XPNode);
dtb.tree.setFocus(dtb.tree.getPathInformation(path));


Adam


Re: Tree2 - a new node & scroll to?

Posted by Sean Schofield <se...@gmail.com>.
I haven't tried using anchors in JSF but presumably that would be the
solution.  Since the nodes are all JSF objects if you can find a way
to add a '#foo' to the URL then you could scroll to the specific
location.  I don't believe there is a way to do this in the JSF spec
but its probably something that should be supported.  Your use case is
a pretty common one (I've experienced this before.)

There is a post on the Sun forum that deals with the issue[1].  Maybe
this is a case for a new attribute for commandLink/commandButton?

Sean

[1] http://forum.java.sun.com/thread.jspa?threadID=490215&messageID=2301780



On 7/31/06, Adam <ad...@softfab.com> wrote:
> Dear All,
>
> we are happily using tree2 & the problem I have is to do with the scrolling.
>
> Is there anyway to tell the scrooling mechanism to scroll to a given node?
>
> i.e. we have a tree which is sufficiently large that it needs a scroll
> bar etc. When we add a new node, it is added to the end of the tree in
> some applications & in a sorted position in others (e.g. the nodes are
> alphabetically sorted).his means that when a user clicks to add a new
> node, he has to scroll down to the end of what might be a large tree
> every time which can get to be a pain for those inserting data.
>
> I add a node as follows:
>
>                 Node XPNode = deb.addChildN();
>                 String path = dtb.getpathToRoot(XPNode);
>                 dtb.tree.expandPath(dtb.tree.getPathInformation(path));
>
> & the node happily expands etc but....that in no way interacts with the
> scrolling. i..e the node is expanded but it's still off the page &
> requires scrolling to get to it.
>
> So how do I (can I?) set the focus to the node added as above such that
> the scrolling mechanism takes the user to that node?
>
> TIA
>
>
> Adam
>
>