1 2 Previous Next 29 Replies Latest reply on Mar 5, 2008 12:40 PM by maxmustang

    TreeNode & selectBooleanCheckbox HOW-to ???

    krasig

      Hi Folks,
      so, tell me how to create tree with chekbox. This was very simple wit Tomahowk but wit RICH face no anything how-to do that.

      In the beginning i try this simple test:

      <rich:tree value="#{tree1.firstTree}" var="node" nodeFace="simpleNode"
       id="tree1">
       <rich:treeNode type="simpleNode" id="treeNode1">
      
       <h:selectBooleanCheckbox value="true"/>
      
      
       </rich:treeNode>
       </rich:tree>

      and in backing bean i have stupid method as:
      public TreeNode getFirstTree() {
       firstTree=new TreeNodeImpl();
       firstTree.setData("a1");
       TreeNodeImpl child = new TreeNodeImpl() ;
       child.setData("a2");
       TreeNodeImpl child2 = new TreeNodeImpl() ;
       child2.setData("a3");
       firstTree.addChild(new Integer(1),child);
       firstTree.addChild(new Integer(2),child2);
      
       return firstTree;
       }


      and now I have tree with two checkboxes but no way to check this boxes.
      What is wrong???



        • 1. Re: TreeNode & selectBooleanCheckbox HOW-to ???
          viggo.navarsete

          Hi Krasig!

          Did you solve this problem? I'm also looking for a tree with checkboxes next to each node in the tree.

          Best Regards,
          Viggo

          • 2. Re: TreeNode & selectBooleanCheckbox HOW-to ???
            krasig

            Hi Viggo.
            No. I can't find solution.
            I switched to tomahawk tree2 and everything works.

            Regards.

            • 3. Re: TreeNode & selectBooleanCheckbox HOW-to ???
              viggo.navarsete

              ok, so the tree2 got the "checkbox feature"?! Can I still use the RealFaces and tomahawk together, or will there be some problems then?

              • 4. Re: TreeNode & selectBooleanCheckbox HOW-to ???
                krasig

                I use RealFaces and tomahawk and no problems.
                Checkboxes is not build on feature in tree2. If you interested i will paste snippet.

                Best Regards.

                • 5. Re: TreeNode & selectBooleanCheckbox HOW-to ???
                  viggo.navarsete

                  I would really be thankful if you would paste a snippet here yes:)

                  By the way, I'm using the JSF/RealFaces in a portlet, hope that will work as well. I'm using the JSFPortletBridge.

                  • 6. Re: TreeNode & selectBooleanCheckbox HOW-to ???
                    krasig

                    Hi Viggo.
                    I never used portlet anf I don't know how this will work but hope that will be fine.

                    1. You must extend TreeNodeBase like this:

                    public class ExtendedTreeNode extends TreeNodeBase {
                    
                     private static final long serialVersionUID = 4597634241450394824L;
                    
                     private boolean checked; // ako ima checkBox, default value = false
                    
                     public ExtendedTreeNode( String type, String description, String identifier, boolean p3, boolean isChecked )
                     {
                     super(type, description, identifier, p3);
                     this.checked = isChecked;
                     }
                     public ExtendedTreeNode() {}
                     public void setChecked(boolean checked) {
                     this.checked = checked;
                     }
                     public boolean isChecked() {
                     return checked;
                     }
                    }
                    
                    


                    in this way, The node wull have propertie "checked" and in JSF we will have:

                    <t:tree2 id="TreeCheckBox" value="#{modal.areaValuesTree}"
                     var="node" varNodeToggler="t" clientSideToggle="true"
                     showRootNode="false">
                     <f:facet name="foo-folder">
                    
                     <h:outputText value="#{node.description}"
                     styleClass="nodeFolder" />
                    
                    
                     </f:facet>
                     <f:facet name="folder">
                     <h:panelGroup>
                     <h:selectBooleanCheckbox value="#{node.checked}" />
                     <h:outputText value="#{node.description}"
                     styleClass="nodeFolder" />
                    
                     </h:panelGroup>
                     </f:facet>
                    ...
                    <t:tree2>


                    And that is . Nowwhen submit tree you mus travel over tree to find all checked nodes. I have method for this:
                    public static ArrayList<String> getSelectedTreeNodes(
                     List<ExtendedTreeNode> child) {
                     ArrayList<String> itemID = new ArrayList<String>();
                    
                     for (int i = 0; i < child.size(); i++) {
                     if (((ExtendedTreeNode) child.get(i)).getChildCount() > 0) {
                     itemID.addAll(getSelectedTreeNodes(((ExtendedTreeNode) child
                     .get(i)).getChildren()));
                     }
                    
                     if (((ExtendedTreeNode) child.get(i)).isChecked() == true) {
                     itemID.add(((ExtendedTreeNode) child.get(i)).getIdentifier());
                     }
                     }
                    
                     return itemID;
                     }


                    GOOD LUCK!


                    • 7. Re: TreeNode & selectBooleanCheckbox HOW-to ???
                      viggo.navarsete

                      Thanks a lot, I will give it a try later tonight:)

                      • 8. Re: TreeNode & selectBooleanCheckbox HOW-to ???
                        viggo.navarsete

                        A quick question: Can I use the Tomahawk components with the JSF RI 1.2 implementation?

                        • 9. Re: TreeNode & selectBooleanCheckbox HOW-to ???
                          krasig

                          My environment:
                          Facelets,
                          JSF 1,2
                          RichFaces,
                          Tomahawk

                          :)

                          • 10. Re: TreeNode & selectBooleanCheckbox HOW-to ???
                            viggo.navarsete

                            Great :)

                            Thanks for all your input krasif!! I'm pretty new to JSF development, but I thought I try it, since I've neved tried a component-based web-framework before.

                            • 11. Re: TreeNode & selectBooleanCheckbox HOW-to ???
                              krasig

                              You are welcome.

                              • 12. Re: TreeNode & selectBooleanCheckbox HOW-to ???
                                viggo.navarsete

                                Hi again krasig,

                                are you using maven to set dependencies to other 3rd party libraries like RichFaces and Tomahawk? If yes, how does your pom.xml look like? I see that ajax4jsf and richFaces have been merged into one project lately, and I would like to take advantage of the new merged project and use the most up-to-date dependencies.
                                In my current pom.xml the dependencies for JSF 1.2, RichFaces and Tomahawk looks like this:

                                <dependency>
                                 <groupId>com.sun.faces.portlet</groupId>
                                 <artifactId>jsf-portlet</artifactId>
                                 <version>1.2.1</version>
                                 </dependency>
                                 <dependency>
                                 <groupId>org.richfaces</groupId>
                                 <artifactId>richfaces</artifactId>
                                 <version>3.0.1</version>
                                 </dependency>
                                 <dependency>
                                 <groupId>org.apache.myfaces.tomahawk</groupId>
                                 <artifactId>tomahawk</artifactId>
                                 <version>1.1.6</version>
                                 </dependency>


                                • 13. Re: TreeNode & selectBooleanCheckbox HOW-to ???
                                  krasig

                                  Hi Viggo,
                                  I don'n use maven for dependecies.
                                  Ajax4jsf and RichFaces will be merged in next release. Now i use last stable releases:
                                  RichFaces 3.0.1 and Ajax4jsf 1.1.1

                                  • 14. Re: TreeNode & selectBooleanCheckbox HOW-to ???
                                    viggo.navarsete

                                    krasig, a couple more questions:
                                    1. I've added the ExtendedTreeNode class to my project, and added the tree to my page. Now when I deploy my application, I first was missing a library,commons-el. When I added it, I got the following error:
                                    java.lang.IllegalStateException: ExtensionsFilter not correctly configured. JSF mapping missing. JSF pages not covered. Please see: http://myfaces.apache.org/tomahawk/extensionsFilter.html
                                    at org.apache.myfaces.renderkit.html.util.AddResourceFactory.throwExtensionsFilterMissing(AddResourceFactory.java:358)

                                    What is required to configure tomahawk? things in web.xml? other things?
                                    Do you have a working example (war-file) where I could w see everything neededt o use the tree2 with checkboxes, including a backing bean?

                                    1 2 Previous Next