aspose file tools*
The moose likes JSF and the fly likes Need to call a method to populate my list, then have that list bound to rich tree Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Need to call a method to populate my list, then have that list bound to rich tree" Watch "Need to call a method to populate my list, then have that list bound to rich tree" New topic
Author

Need to call a method to populate my list, then have that list bound to rich tree

Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

I have the method written to populate the list, and when I call the method and print the alues it doesshow that the list was populated like I want. So I thought the next part would be simple, I would just have setter and getter for the list and bind this to my tree. But when i did this I get an error saying

roots="#{tempTreeBean.ids}": Error reading 'ids' on type testContainer.Temp

So it looks like to me that teh tree is trying to pull the vaues from my list before the method to populate the list is being invoked. So how do I tell my rich tree to call the method to load the list before trying to add that list as the branches of the tree? I tried just putting a method call in the getter to load the list, but no good. I am wondering if there is just some attribute I can add to the rich tree tag that will tell it to first call the method to load the lst with values, and then try to use that list to populate the branches

edit - essentially Im needing to tell my jsf page "invoke this method to load the list before you do anything else, then use this list to populate the tree"


True wisdom is in knowing you know nothing - Socrates
Kavita Tipnis
Ranch Hand

Joined: Sep 21, 2008
Posts: 177
First check whether your getter/setter has a valid signature. I think it should not be static.
If you do not wish to call the method that populates your list everytime you invoke the getter put it in the BackingBean constructor


If your TempTreeBean is in request scope, the loadList() will be invoked per request, if it is in session scope then per session


Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

No, the getter isnt static.
Here is the code:



When I call the loadNodes method followed by the print method it prints out the deviceIds like I expect, so it looks like everything is working as intended. However if I bind ids to my tree it gives me this stack:

javax.el.ELException: /test/treetest.xhtml @18,75 roots="#{tempTreeBean.ids}": Error reading 'ids' on type testContainer.Temp
com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:76)
org.richfaces.component.html.HtmlRecursiveTreeNodesAdaptor.getRoots(HtmlRecursiveTreeNodesAdaptor.java:181)
org.richfaces.component.UIRecursiveTreeNodesAdaptor.getData(UIRecursiveTreeNodesAdaptor.java:55)
org.richfaces.component.UITreeNodesAdaptor$1.getData(UITreeNodesAdaptor.java:54)
org.richfaces.model.StackingTreeModel.getDataModel(StackingTreeModel.java:83)
org.richfaces.model.StackingTreeModel.doWalk(StackingTreeModel.java:309)
org.richfaces.model.StackingTreeModel.walk(StackingTreeModel.java:381)
org.richfaces.component.UITree.walk(UITree.java:422)

Thats not all of it but it is the beginning. But when I click on line 76 or 181 there it tells me the source isnt attached, and when I try to figure out where the source is to attahc I have no luck with it.

Someone else has suggested using @PostConstruct annotation to resolve this so Im looking into that now but it is the first time Ive heard of that
Kavita Tipnis
Ranch Hand

Joined: Sep 21, 2008
Posts: 177
For debugging purpose, just add to ids manually(as in "1","2") , that should just be a 2 min work, check if that is throwing any error
Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

I did try that actually and it did work. ANd when I tried the @PostConstruct I now get

javax.servlet.ServletException: java.lang.IllegalArgumentException: Invalid PostConstruct annotation
javax.faces.webapp.FacesServlet.service(FacesServlet.java:277)
org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:390)
org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517)

So now my only guess is that method just doesnt want to work when invoked from the server, only the client, but that is just a pure guess really.

Here is the method that is giving all the hassle:



Then I have a main method in another class to invoke the loadnodes and print methods:



And the result is
Printing ids list: [exampleDevice1]

Here are the other two classes that are instanced in temp:





But now were getting into my other problem, which is that it is not easy to just look at all of this code and find the problem, one would need to test it, which is what I am supposed to be doing. Ce la vie
John Arevalo
Greenhorn

Joined: Jul 29, 2009
Posts: 2
PostConstruct annotation should be applied to methods without throws Exceptions, void return and no params. Only one method can be postconstruct
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need to call a method to populate my list, then have that list bound to rich tree
 
Similar Threads
JSF 2.0 + Primefaces Richtext Editor
trouble parsing stream or string into xml
Trying to add string values to a list or some type of collection through iterator
Very simplified version of rich tree with list data source still giving me a blank page...
@OneToMany/ManyToOne and @OneToOne relationship between same entities.