Get your CodeRanch badge!*
The moose likes JSF and the fly likes Need my rich:tree to be re loaded when I add a new entity to it Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Need my rich:tree to be re loaded when I add a new entity to it" Watch "Need my rich:tree to be re loaded when I add a new entity to it" New topic
Author

Need my rich:tree to be re loaded when I add a new entity to it

Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

I have a rich:Tree that lists projects, devices and channels, one under the other. Its finally working great, plus I have the code and pages in place to either add new entities to any of this stuff, or edit the ones that are there.

Of course once you edit or add something, the rich:tree needs to change to reflect this. The tree is getting its data from a web service that holds xml btw.

But as of right now, the only way i can get this change to show up, is after I add or edit something, I have to close down eclipse and restart it, as well as tomcat, then load the page fresh.

Now I have heard of things like listeners that I can add to my submit buttons maybe to have this done on its own. Essentially I need that rich:tree to reload every time a submit button is pressed. Can someone give me a keyword that I should search for that I can research that will do what I need? It will be a great help to have a place to start with this, other than "listener"

Here is one of the pages if it helps, this page is a rich:tree on the left side, and then in the main content a set of tabs, one each for project, device and channel. Clicking on the rich:tree changes what is inside of each tab, and then from those tabs you can edit each individual entity.

How can I get my rich:tree(s) to register these changes and re load to reflect them after one of the submit buttons is pressed?



True wisdom is in knowing you know nothing - Socrates
Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

Well I made some sort of progress...

I did this with my submit button:



the action sends the new data to the web service to be stored and works fine. The actionListener reloads the List of Objects bound to the tree with the new values, including the project update after this submit button has been pressed. This works too, I know because I used System.out code to make sure the new changes were being reflected.

Then I have the reRender attribute set to tree, which is the id of my rich:tree (rich:tree id="tree")

But when the submit button is pressed, it does everything, but I believe it is reRendering the tree BEFORE the actionListener completes. If I dont do anything, just hit that submit button a second time, the tree does get reRendered with the new data. So obviously everything is working, just not in the order I need it to.

So is there a way to tell my the commandButton, to first do the actionListener, which usually takes 3-5 seconds to run through completely, and then reRender the tree?

Or is there simply a better way to handle this?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

Matt, you're one busy little bee!

I think you need to study up on the JSF lifecycle so that you have a better grasp on what happens when, and in particular the difference between "normal" and "immediate" requests.

I don't think it's wise to mix actions and actionListeners in any event, although as far as it goes, I believe the official take is that the actionListeners include a built-in listener that fires the action handler (and I think it's always supposed to happen last).

In general, I think listeners are overused in JSF, and the only explanation I have for that is that I suspect that action handlers were a later addition to the architecture, so a lot of stale examples are out there polluting the Internet docs. At a minimum, I'll say that the early days of JSF were so volatile that for a long time, I'd despaired of ever being able to make sense of it (I got better). They do have their uses, of course. Especially if you need more than one action to be fired.

Normally, I'd update the tree datamodel in the "updateProject" method. In other words, have updateProject invoke reloadTree. To limit the display update, I'd attach the reRender to the commandButton element itself, and probably tack on an 'ajaxSingle="true"' just for good measure.

Customer surveys are for companies who didn't pay proper attention to begin with.
Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

Hmm, I didnt think to combine the methods. Ill give that a try. I did try to put the reRender attribute on my commandButton at first, but it didn't seem to work. The method would run to fire the actionListener, which reLoaded the List with data(the list bound to the tree), and then the tree would flash which means it got reRendered, but it wasn't loading in the new List for some reason.

I have it working for now, but I am going to try your method. Thanks a lot

edit - Oh and Im busy because Im doing the work of three team members ha. Its not even worth trying to get them to do their part anymore, because it would take me longer to catch them up than to just do it myself. But this project officially ends in 4 days, at which point I pass this on to the company. Then I plan to use y knowledge Ive gained to start my own site, that will be used for trying out new things, and function as a sort of resume for when I graduate in May.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

Matt Kohanek wrote:Hmm, I didnt think to combine the methods. Ill give that a try. I did try to put the reRender attribute on my commandButton at first, but it didn't seem to work. The method would run to fire the actionListener, which reLoaded the List with data(the list bound to the tree), and then the tree would flash which means it got reRendered, but it wasn't loading in the new List for some reason.

I have it working for now, but I am going to try your method. Thanks a lot

edit - Oh and Im busy because Im doing the work of three team members ha. Its not even worth trying to get them to do their part anymore, because it would take me longer to catch them up than to just do it myself. But this project officially ends in 4 days, at which point I pass this on to the company. Then I plan to use y knowledge Ive gained to start my own site, that will be used for trying out new things, and function as a sort of resume for when I graduate in May.


I was going to ask you what kind of slacker you were to only be doing the work of 3 people in this day and age, but it looks like you're a student.

Oh the carefree, idle days of academy!
Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

Yeah, a student, but this project is actually for a worldwide company for their corporate website. There is a big design challenge at my school every year held by this company, and my proposal won so thats why Im doing this project. I say "my proposal", because all my teammates did was fill out their section of "The Team" on it hahaha. I guess I shouldve seen that as a sign of things to come
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need my rich:tree to be re loaded when I add a new entity to it
 
Similar Threads
Having issues reRendering a map when a rich:tree node is clicked on(SOLVED)
Problem getting richfaces tree to display
having clicking on a treeNode from rich:tree change ui:define content (need help)
What would be best way to handle how clicking on something changes a content pane...
need nodes on rich:tree to not be auto selected, only selected when clicked on.