2 Replies Latest reply: Jul 5, 2012 10:26 AM by lukas.b272 RSS

How to commit JTree to <rich:tree>

lukas.b272 Newbie

Hello Community,

 

I have the following problem and I would be happy if you could give me some advice.

I have an existing Java application (JDK) which generates a JTree (with several hundred treenodes). Now, this tree should be transfered to a html web site.

Best case would be a simple transfer the model of the JTree component to the RichFaces html tree component <rich:tree>, but i can’t find any examples for that, only some with filling a <rich:tree> from a xml file ( this would be not ideal).

Is there any other way, maybe a direct way like written as my best case scenario?

 

Thank you for your help (and time)!

 

Greetings from Germany

  • 1. Re: How to commit JTree to <rich:tree>
    Brendan Healey Master

    It doesn't sound too difficult although I don't have any code written that does this. Assuming that you want to display

    instances of class MyClass as tree nodes you need to build a list of root nodes first and I guess you just need to look

    through the API to figure this out. On the richfaces side of things it's pretty simple:

     

    - public class MyClass implements Serializable, javax.swing.tree.TreeNode {

     

    - you will need to implement various abstract methods, exactly which ones will depend on your specific circumstances.

        A reasonable approach is to throw new UnsupportedOperationException("method name") initially and only implement

        the method if you see it being called. Your IDE should have an 'implement all abstract methods' function.

     

    - private List<TreeNode> rootNodes = new ArrayList<>(); // Java 7 diamond notation, use <TreeNode> for Java 5/6

     

    - List<MyClass> myList = ... build a list of MyClass from the jTree

     

    - rootNodes.clear();

    - rootNodes.addAll(myList);

     

    - <rich:tree value="#{bean.rootNodes}" ...

     

    See the showcase example here: http://showcase.richfaces.org/richfaces/component-sample.jsf?demo=tree&skin=blueSky

     

     

    Regards,

    Brendan.

  • 2. Re: How to commit JTree to <rich:tree>
    lukas.b272 Newbie

    Hello Brendan,

     

    at first sorry for my late answer and thank your very much for your help!

     

    I tried out the example you linked, at first everything works fine but the result is just simple text like this:

     

    Rootnode

    Treenode

    Leafnode

    Rootnode2

    Treenode2

    Leafnode2

     

     

    But i also got some error messages:

     

     

    1. Browser error message:

     

    Richfaces is undefined

    Line 21 Char 1

     

    this is line 21 from the HTML code:

     

    </span>
    </span>
    </div>
    </div>
    </div>
    </div>
    <input type="hidden" name="j_idt6:tree__SELECTION_STATE" id="j_idt6:tree__SELECTION_STATE" class="rf-tr-sel-inp" value="" />
    <script type="text/javascript">
    new RichFaces.ui.Tree("j_idt6:tree",{"toggleType":"client","selectionType":"ajax","ajaxSubmitFunction":"RichFaces.ajax(source,event,{\"clientParameters\":params,\"complete\":complete,\"incId\":\"1\"} )"} );
    </script>
    </div>
    <input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="402519301787076934:5641689052140157529" autocomplete="off" />

     

    Sorry for the bad formatting but as you know its generated by jsf...

     

     

    2. Error from Tomcatlog

     

    Exception starting filter richfaces

    java.lang.ClassNotFoundException: org.ajax4jsf.Filter

    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)

    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523)

    at

    .....

     

    followed by other errors like this

     

    Exception sending context initialized event to listener instance of class com.sun.faces.config.ConfigureListener

    java.lang.RuntimeException: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! duplicate key: class javax.faces.validator.DoubleRangeValidator

    at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:292)

    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4723)

    at ...

     

     

     

    at this point i dont know how to fix the problem.

     

     

    Thank you

     

    Regards,

    Lukas.