• Post Reply Bookmark Topic Watch Topic
  • New Topic

ReRender specific RichFaces TreeNode

 
Aj Jaro
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Currently after a treenode is edited using the editCustomerItem component, the entire RichFaces tree is updated and reRendered. Is it possible to only reRender the specific TreeNode that was edited instead of the entire Tree? The tree gets very large and we're looking to optimize the reRender process.

I've looked and attempted the nodeSelectListener attribute of the tree combined with the ajaxKeys/ajaxNodeKeys attribute, but they always failed with the 'java.lang.IllegalStateException: No tree element available or row key not set!
at org.richfaces.model.TreeDataModel.isLeaf(TreeDataModel.java:296)
at org.richfaces.component.UITree.isLeaf(UITree.java:534)
at org.richfaces.renderkit.NodeRendererBase.initializeLines(NodeRendererBase.java:156)
at org.richfaces.renderkit.html.TreeNodeRenderer.doEncodeBegin(TreeNodeRenderer.java:101)'.



 
Tim Holloway
Bartender
Posts: 18408
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is old code and it's for RichFaces 3, but I had a similar problem where the complete expanded menu list ran something like 3MB, so I had to minimize the network traffic.
 
Aj Jaro
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks so much for the response.

Which part of the code you pasted handled when the node needed to be rerendered? Can you paste the java code? Maybe that will make it clearer to me.
 
Tim Holloway
Bartender
Posts: 18408
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
None of it is directly involved with re-rendering. The TreeNode is Model/View/Controller with a UI model shadowing a data model.

I'm afraid that my code is rather long and messy and probably has some dead-ends in it, since it was very much a learning process from documentation that was written by someone whose native language was something like Russian.

From what I can tell, the processSelection listener doesn't do anything. The adviseNodeOpened ("treeState") method checks the UI model for a menu node and determines whether its children should be displayed. The changeExpandListener does a lazy fetch of child data model data on the server side so that the entire menu doesn't have to be constructed before anything's displayed. Instead I built the top-level list and then added sub-elements when people opened (expanded) their parent elements.

Actual rendering is done by the renderer (since it's MVC), and the backing bean logic simply defines whether a given node is to be rendered. Qualified, as you can see, by some EL on the that filters what's acceptable for a given user.

Somewhere there should be an application-scope master datamodel, since the same menu is shared by all users. This pairs with the UI model, which is a session object that indicates what menu items a given user has expanded (or not).

Tying it all together is a PostbackPhaseListener. Its exact function is unclear to me, but I don't do background listeners unless I have to, so it was presumably something I got from the RichFaces docs. I think it's got a Map that indicates what UI model objects are supposed to be in view, using a unique identifier for each possible displayed menu node.
 
Aj Jaro
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim, thanks so much for your help so far. Do you know if there is a way to update/rerender a treenode after the user has made a modification to it? Otherwise I'm stuck rerendering the entire tree and that is just a waste.

Thanks!
 
Tim Holloway
Bartender
Posts: 18408
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe that there are 3 different options on re-rendering although I cannot remember the details. The one which should require the least overhead is AJAX.

AJAX can handle the opening and closing of nodes on the display fairly well. If you're actually changing the content of the tree from somewhere outside the hierarchy, you'd need to be a able to do a standard RichFaces reRender, which means supplying the requesting element with a unique JSF ID(s) to be re-rendered. In the example I gave, that's a problem, since I'm only using a single sub-item and therefore the same ID would apply for all of its rendered levels. I think that if you defined levels more explicitly (with unique IDs) that might help.

It's likely to require some trial and error, and you may not be able to get what you want. Some complex structures are essentially atomic. For example, you cannot re-render a single row in a dataTable, you have to re-render the entire table.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!