voyent
How to make Tree component refresh after server-side TreeModelEvent?  XML
Forum Index -> Components
Author Message
abramkelly


Joined: 21/Aug/2007 00:00:00
Messages: 12
Offline


I have a page with an ice:tree component, where the value of the tree is a swing TreeModel, just like in the demo. However, unlike the demo, my TreeModel is constantly changing based on a variety of factors which have nothing to do with the user. Right now, my tree looks great and is perfectly synchronized with reality the moment a session begins, and never again, because no one has informed my Tree component that anything exciting is happening.
Do I have to do something special to make the component continuously aware of it's own value?

My code looks something like this:

Code:
 <f:view>
 <ice:form>
 <ice:tree var="node" value="#{bean.model}">
  <ice:treeNode link="#{node.userObject.
 


The 'bean' variable is a session-scoped managed bean which has a TreeModel property. While the tree is technically inside of a form, the form is never submitted because there would be no point - the only user interaction with the tree is expand, contract, or click, in which case some other stuff happens... Point is, the state of the form is never going to change as part of the application; however, I'd be happy to submit it partially, fully, or continuously 8 times per second if it would make the UI wake up and realize that it's value is now totally different.

So, my question is, what do I need to do to get some visible change on my tree when the model fires an event? Should I be using a render request instead of expecting the component to update automatically? If so, which object should be renderable?

Any suggestions greatly appreciated.
abramkelly


Joined: 21/Aug/2007 00:00:00
Messages: 12
Offline


BTW, my code didn't get cut off, it's just that the rest is not poignant to my current situation. I leave the node body to the reader's imagination.
mark.collette


Joined: 07/Feb/2005 00:00:00
Messages: 1692
Offline


If you look at the component-showcase, either the page on the progress bar, or the page with the file upload, which also uses a progress bar, and scan for references to "RenderManager" you'll see how to do ICEfaces Ajax server push.

There's a related explanation in the Timezone Tutorial Step 3, but it sets up an IntervalRenderer, whereas you want an OnDemandRenderer.
[Email]
dim5b

Joined: 13/Sep/2007 00:00:00
Messages: 42
Offline


Seems i have the same problem with abramkelly followed the component-showcase example... and by implementing the tree in the getModel() method ..... and not in the constructor of my bean i can now see the render effect since the value"#{bean.model}" in my jspx gets rendered.....

however the tree will not expand/minimise if rootObject.setExpanded(true);

what am i doing wrong

thanks in advance...
abramkelly


Joined: 21/Aug/2007 00:00:00
Messages: 12
Offline


OK, so I tried using the Renderable interface just like they do in the tutorials. It's a little tricky to know if I'm doing it right, owing to the contrast between constructing a data model from assessments of network vulnerability across multiple domains, and making a thread sleep while it counts to a thousand, but I think I'm on the right track.
I have my backing bean implement Renderable, and send the render request thing as soon as it receives the RenderManager, like so:
Code:
 public void setRenderManager(RenderManager manager) {
  this.onDemandRenderer = manager.getOnDemandRenderer( "really-big-tree-group");
  onDemandRenderer.add(this);
  onDemandRenderer.requestRender();
 }


My bean is also a listener for my model's TreeModelEvents, so I called requestRender on each tree event from the data model, since this data being up-to-date is currently my reason for existing, and there's no such thing as too up-to-date.
Code:
 public void treeStructureChanged(TreeModelEvent event) {
  onDemandRenderer.requestRender();
 }


This caused a continuous stream of LifeCycle exceptions. Like, literally continuous. I couldn't find any actual log output due to the endless waves of D2D-Handlers rebuking my thoughtlessness. So I took out the render requests on the tree listeners. Now it looks like the above method with the the middle line commented out, so that each time my data model fires a change event, absolutely nothing happens.
Only that's not what happens; now my tree updates whenever you expand or contract a node (but, interestingly, not when you click the links or do anything else besides expand or contract nodes). So, like, nothing happens for a while, then you expand a node, and suddenly half the tree has disappeared. This is definitely way better than refreshing only at the beginning of the session, but still not quite the same as "real time".

So now I am wondering 2 things: first, since I am calling requestRender exactly one time per session, why is it now synchronizing on every expand/contract event? and second, obviously, I am wondering how to make it synchronize when the actual events occur, without, you know, blowing up.

Thanks,
ak
dim5b

Joined: 13/Sep/2007 00:00:00
Messages: 42
Offline


Can someone clarify one thing....when renderer.requestRender(); is called the current state of the model will be rendered again... and icefaces will look to see which components have been changed. Since in my case the nodes are those that change

<ice:tree id="tree" value="#{roster.model}" var="item"> the model will be updated....

is my reasoning correct.. since by implementing -as mentioned in previous post- in the getModel() method i can see the render effect on my treenode but loose Node expansion functionality...

thanks
Dimitri
mark.collette


Joined: 07/Feb/2005 00:00:00
Messages: 1692
Offline


I wouldn't call the OnDemandRenderer for every TreeModelEvent, since user interactions with the tree, that will already result in a render, cause TreeModelEvents. Rather, whatever code gets your new data, and updates your tree model, should call the OnDemandRenderer, after it's done updating your model, in a synchronized fashion.
[Email]
andrea.biasillo

Joined: 03/Sep/2010 05:59:42
Messages: 19
Offline


I have the same problem:

implementing the tree in the getModel() method ..... and not in the constructor , i can now see the render effect since the value"#{bean.model}" in my jspx gets rendered.....

however the tree will not expand/minimise (it is rendered open)

what am i doing wrong

thanks in advance...

Andrea.
andrea.biasillo

Joined: 03/Sep/2010 05:59:42
Messages: 19
Offline


solved, no, i did not
frk-7

Joined: 20/Jan/2020 06:25:50
Messages: 1
Offline


Hi ,
i had a similar problem that i solved in this way;

I extracted the tree's component from the context


FacesContext ctx = FacesContext.getCurrentInstance();
Application app = ctx.getApplication();
app.evaluateExpressionGet (ctx,"your_component",TreeBean.class)

from that i took the DefaultMutableTreeNode then removeAllChildren()

hope it helps
 
Forum Index -> Components
Go to:   
Powered by JForum 2.1.7ice © JForum Team