voyent
My Tree is not working  XML
Forum Index -> General Help
Author Message
allanbruno

Joined: 30/Dec/2008 00:00:00
Messages: 38
Offline


I'm using the Icefaces 1.7.1 with Seam 2.1.1 and my tree component does't work.

Here is my simple example:

Code:
 
 @Entity
 @Name("tree")
 @Scope(ScopeType.APPLICATION)
 public class TreeBean {
 
     // tree default model, used as a value for the tree component
     private DefaultTreeModel model;
 
  // default node icons for xp thme
     private static final String XP_BRANCH_CONTRACTED_ICON = "./xmlhttp/css/xp/css-images/tree_folder_open.gif";
     private static final String XP_BRANCH_EXPANDED_ICON = "./xmlhttp/css/xp/css-images/tree_folder_close.gif";
     private static final String XP_BRANCH_LEAF_ICON = "./xmlhttp/css/xp/css-images/tree_document.gif";
 
     
     public TreeBean(){
         // create root node with its children expanded
         DefaultMutableTreeNode rootTreeNode = new DefaultMutableTreeNode();
         IceUserObject rootObject = new IceUserObject(rootTreeNode);
         rootObject.setText("DAM");
         rootObject.setExpanded(true);
         rootObject.setBranchContractedIcon(XP_BRANCH_CONTRACTED_ICON);
         rootObject.setBranchExpandedIcon(XP_BRANCH_EXPANDED_ICON);
         rootObject.setLeafIcon(XP_BRANCH_LEAF_ICON);
         rootTreeNode.setUserObject(rootObject);
 
         // model is accessed by by the ice:tree component
         model =  new DefaultTreeModel(rootTreeNode);
 
         String valores[] = {"Operações","Demais dados da operação","Demais debitos fiscais", "Documentos Fiscais", "Informações complementares", "Demonstrativo", "Indústria Incentivada", "Resumo da Declaração"};
       
         
         // 0, 1, 6
         // add some child notes
         
         // add some child notes
         for (int i = 0; i < valores.length; i++) {
         	 DefaultMutableTreeNode branchNode = new DefaultMutableTreeNode();
              IceUserObject branchObject = new IceUserObject(branchNode);
              branchObject.setText(valores[i]);
              branchObject.setBranchContractedIcon(XP_BRANCH_CONTRACTED_ICON);
              branchObject.setBranchExpandedIcon(XP_BRANCH_EXPANDED_ICON);
              branchObject.setLeafIcon(XP_BRANCH_LEAF_ICON);
              branchObject.setLeaf(true);
              branchNode.setUserObject(branchObject);
              rootTreeNode.add(branchNode);
              // add some more sub children
              for (int k = 0; k < 2; k++) {
                  DefaultMutableTreeNode subBranchNode = new DefaultMutableTreeNode();
                  IceUserObject subBranchObject = new IceUserObject(subBranchNode);
                  subBranchObject.setText("sub-node-" + i + "-" + k);
                  subBranchObject.setBranchContractedIcon(XP_BRANCH_CONTRACTED_ICON);
                  subBranchObject.setBranchExpandedIcon(XP_BRANCH_EXPANDED_ICON);
                  subBranchObject.setLeafIcon(XP_BRANCH_LEAF_ICON);
                  branchObject.setLeaf(true);
                  subBranchNode.setUserObject(subBranchObject);
                  subBranchNode.setAllowsChildren(false);
                  branchNode.add(subBranchNode);
              }
             
        
         }
         
     }
 
     /**
      * Gets the tree's default model.
      *
      * @return tree model.
      */
     public DefaultTreeModel getModel() {
         return model;
     }
 



My index.xhtml

Code:
 
 <f:view xmlns:h="http://java.sun.com/jsf/html"
     xmlns:f="http://java.sun.com/jsf/core"
     xmlns:ice="http://www.icesoft.com/icefaces/component">
 
     <ice:outputDeclaration doctypeRoot="HTML"
         doctypePublic="-//W3C//DTD HTML 4.01 Transitional//EN"
         doctypeSystem="http://www.w3.org/TR/html4/loose.dtd" />
 
     <html>
     <head>
         <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></meta>
         <title>SEFAZ / AM - DAM Eletronica 2008 - V1</title>
         <link href="./xmlhttp/css/xp/xp.css" rel="stylesheet" type="text/css" />
     </head>
     <body>
         <h2>Declaracao</h2>
         <ice:form>
             <ice:panelGroup styleClass="treeContainer">
                 <!--
                     This is a very basic tree comprising of only text nodes.  The
                     expand and contract images are rendered because the "imageDir"
                     attribute on the tree component has been set to a known path.
                 -->
                 <ice:tree id="tree"
                       value="#{tree.model}"
                       var="item"
                       hideRootNode="false"
                       hideNavigation="false"
                       imageDir="./xmlhttp/css/xp/css-images/">
                 <ice:treeNode>
                     <f:facet name="icon">
                         <ice:panelGroup style="display: inline">
                              <h:graphicImage value="#{item.userObject.icon}"/>
                         </ice:panelGroup>
                     </f:facet>
                     <f:facet name="content">
                         <ice:panelGroup style="display: inline">
                             <ice:commandLink
                                     value="#{item.userObject.text}"/>
                         </ice:panelGroup>
                     </f:facet>
                 </ice:treeNode>
             </ice:tree>
             </ice:panelGroup>
         </ice:form>
     </body>
     </html>
 </f:view>
 



On the screen is the displayed the tree, but where is the sub-nodes?

The sub-nodes doesn't works...

Can anyone help?

Thanks!
judy.guglielmin

Joined: 20/Feb/2007 00:00:00
Messages: 1396
Offline


First thing, application-scoped beans are not synchronized, so you would have to add that annotation, but I am wondering why you would want the tree in application scope? This means that everyone who uses the tree would be seeing the same state...I'm not sure this is desirable.

Also, usually what you want to define as an entity is the object within the tree (eg: employee) and this would have the entity notation. Your treemodel would then be made up of a collection of employees.

Please review further the example in seam-comp-showcase. I would suggest a Session-scoped tree to begin with or conversation if you are familiar with conversation managed beans.
allanbruno

Joined: 30/Dec/2008 00:00:00
Messages: 38
Offline


Well judy, I tried what you suggest, and doesn't works. I just try to do the example of Tutorial "tree-style-tutorial"... So simple, and the sub-nodes is not displayed...

Thanks!
jguglielmin

Joined: 20/Jul/2007 00:00:00
Messages: 181
Offline


Attach a (very simple) example of what you are trying to achieve). Are you sure that you are not losing the state perhaps by not propagating conversations properly? Are you sure that your sub-node is not null? If you have an entity that has a relationship to a list of other entities (I am assuming this is the case with sub-node?), then perhaps that list is empty.
allanbruno

Joined: 30/Dec/2008 00:00:00
Messages: 38
Offline


Judy, if I want don't define a object like a "Employee" on sub-node?

It is obrigate to use a object on a sub-node?

My code is simple:

Code:
 
 package arvore;
 
 import java.io.Serializable;
 
 import javax.swing.tree.DefaultMutableTreeNode;
 import javax.swing.tree.DefaultTreeModel;
 
 import org.jboss.seam.ScopeType;
 import org.jboss.seam.annotations.Name;
 import org.jboss.seam.annotations.Scope;
 
 import com.icesoft.faces.component.tree.IceUserObject;
 
 /**
  * <p/>
  * A basic backing bean for a ice:tree component.  The only instance variable
  * needed is a DefaultTreeModel Object which is bound to the icefaces tree
  * component in the jspx code.</p>
  * <p/>
  * The tree created by this backing bean is used to control the selected
  * panel in a ice:panelStack.
  * </p>
  */
 @Name("tree")
 @Scope(ScopeType.SESSION)
 public class TreeBean implements Serializable{
 
     // tree default model, used as a value for the tree component
 
     private DefaultTreeModel model;
     private static final String XP_BRANCH_CONTRACTED_ICON = "./xmlhttp/css/xp/css-images/tree_folder_open.gif";
     private static final String XP_BRANCH_EXPANDED_ICON = "./xmlhttp/css/xp/css-images/tree_folder_close.gif";
     private static final String XP_BRANCH_LEAF_ICON = "./xmlhttp/css/xp/css-images/tree_document.gif";
 
 
     public TreeBean() {
 
     	 // create root node with its children expanded
         DefaultMutableTreeNode rootTreeNode = new DefaultMutableTreeNode();
         IceUserObject rootObject = new IceUserObject(rootTreeNode);
         rootObject.setText("Root Node");
         rootObject.setExpanded(true);
         rootObject.setBranchContractedIcon(XP_BRANCH_CONTRACTED_ICON);
         rootObject.setBranchExpandedIcon(XP_BRANCH_EXPANDED_ICON);
         rootObject.setLeafIcon(XP_BRANCH_LEAF_ICON);
         rootTreeNode.setUserObject(rootObject);
 
         // model is accessed by by the ice:tree component
         model = new DefaultTreeModel(rootTreeNode);
 
         // add some child notes
         for (int i = 0; i < 3; i++) {
             DefaultMutableTreeNode branchNode = new DefaultMutableTreeNode();
             IceUserObject branchObject = new IceUserObject(branchNode);
             branchObject.setText("node-" + i);
             branchObject.setBranchContractedIcon(XP_BRANCH_CONTRACTED_ICON);
             branchObject.setBranchExpandedIcon(XP_BRANCH_EXPANDED_ICON);
             branchObject.setLeafIcon(XP_BRANCH_LEAF_ICON);
             branchObject.setLeaf(true);
             branchNode.setUserObject(branchObject);
             rootTreeNode.add(branchNode);
             // add some more sub children
             for (int k = 0; k < 2; k++) {
                 DefaultMutableTreeNode subBranchNode = new DefaultMutableTreeNode();
                 IceUserObject subBranchObject = new IceUserObject(subBranchNode);
                 subBranchObject.setText("sub-node-" + i + "-" + k);
                 subBranchObject.setBranchContractedIcon(XP_BRANCH_CONTRACTED_ICON);
                 subBranchObject.setBranchExpandedIcon(XP_BRANCH_EXPANDED_ICON);
                 subBranchObject.setLeafIcon(XP_BRANCH_LEAF_ICON);
                 branchObject.setLeaf(true);
                 subBranchNode.setUserObject(subBranchObject);
                 branchNode.add(subBranchNode);
             }
         }
         
     }
 
     /**
      * Gets the tree's default model.
      *
      * @return tree model.
      */
     public DefaultTreeModel getModel() {
         return model;
     }
 }
 
 



index.xhtml
Code:
 <f:view xmlns:h="http://java.sun.com/jsf/html"
         xmlns:f="http://java.sun.com/jsf/core"
         xmlns:ice="http://www.icesoft.com/icefaces/component">
 
     <ice:outputDeclaration doctypeRoot="HTML"
                            doctypePublic="-//W3C//DTD HTML 4.01 Transitional//EN"
                            doctypeSystem="http://www.w3.org/TR/html4/loose.dtd"/>
 
     <html>
     <head>
         <meta http-equiv="Content-Type"
               content="text/html; charset=iso-8859-1"></meta>
         <title>Tree Component Tutorial</title>
         <link href="./xmlhttp/css/xp/xp.css" rel="stylesheet"
               type="text/css"/>
     </head>
 
     <body>
     <h2>Tree Style  Example</h2>
     <ice:form>
 
         <!-- first column, for tree navigation -->
         <ice:panelGroup style="border: 1px solid gray; height: 300px;">
             <!--
                 Fully styled Xp themed tree.
             -->
             <ice:tree id="tree"
                       value="#{tree.model}"
                       var="item"
                       hideRootNode="false"
                       hideNavigation="false"
                       imageDir="./xmlhttp/css/xp/css-images/">
                 <ice:treeNode>
                     <f:facet name="icon">
                         <ice:panelGroup style="display: inline">
                              <h:graphicImage value="#{item.userObject.icon}"/>
                         </ice:panelGroup>
                     </f:facet>
                     <f:facet name="content">
                         <ice:panelGroup style="display: inline">
                             <ice:commandLink
                                     value="#{item.userObject.text}"/>
                         </ice:panelGroup>
                     </f:facet>
                 </ice:treeNode>
             </ice:tree>
         </ice:panelGroup>
 
     </ice:form>
     </body>
     </html>
 </f:view>
 
 



It's like the Tutorial on this site... =(
allanbruno

Joined: 30/Dec/2008 00:00:00
Messages: 38
Offline


It's work Judy.

I use a bean like example. But, on tutorial, is not used a Bean, and just works, show a title.

Thanks a lot one more time!

Best regards.
felipebbarbosa

Joined: 16/Feb/2011 07:12:37
Messages: 4
Offline


I know I've spent a long time since you posted, but you show me how the code was corrected. I'm having the same problem here and can not find the solution. Thanks.
judy.guglielmin

Joined: 20/Feb/2007 00:00:00
Messages: 1396
Offline


Just saying "something is not working" doesn't really provide a lot of info. This example is from 2009 and if you look closely the user was importing the "swing" classes for the nodes (rather than the jsf classes).

If the tree component is not working for you, you really should review the appropriate version of component-showcase (there are versions for jsp, jsf, portlets and seam) and it's version of the tree example. Perhaps modify this example for the functionality you are looking for, and then post any problems you are having using code snippets.
felipebbarbosa

Joined: 16/Feb/2011 07:12:37
Messages: 4
Offline


Yes, I understand. I published because the problem is very similar to mine. But so it is difficult to help, right? =) So here we go ...

I'm using JSF 2.0 with ICEfaces 2 and this is my Managed Bean:

Code:
 import javax.faces.bean.ManagedBean;
 import javax.faces.bean.SessionScoped;
 import javax.swing.tree.DefaultMutableTreeNode;
 import javax.swing.tree.DefaultTreeModel;
 
 import com.icesoft.faces.component.tree.IceUserObject;
 
 @ManagedBean(name="tree")
 @SessionScoped
 public class TreeBean {
 		
 	// tree default model, used as a value for the tree component
 	private DefaultTreeModel model;
 	
 	// default node icons for rime theme
 	private static final String RIME_BRANCH_CONTRACTED_ICON = "./resources/css/rime/css-images/tree_folder_open.gif";
 	private static final String RIME_BRANCH_EXPANDED_ICON = "./resources/css/rime/css-images/tree_folder_close.gif";
 	private static final String RIME_BRANCH_LEAF_ICON = "./resources/css/rime/css-images/tree_document.gif";
 	
 	public TreeBean() {
 		
 		 // create root node with its children expanded
         DefaultMutableTreeNode rootTreeNode = new DefaultMutableTreeNode();
         IceUserObject rootObject = new IceUserObject(rootTreeNode);
         rootObject.setText("Root Node");
         rootObject.setExpanded(true);
         rootObject.setBranchContractedIcon(RIME_BRANCH_CONTRACTED_ICON);
         rootObject.setBranchExpandedIcon(RIME_BRANCH_EXPANDED_ICON);
         rootObject.setLeafIcon(RIME_BRANCH_LEAF_ICON);
         rootTreeNode.setUserObject(rootObject);
 
         // model is accessed by by the ice:tree component
         model = new DefaultTreeModel(rootTreeNode);
 
         // add some child notes
         for (int i = 0; i < 3; i++) {
             DefaultMutableTreeNode branchNode = new DefaultMutableTreeNode();
             IceUserObject branchObject = new IceUserObject(branchNode);
             branchObject.setText("node-" + i);
             branchObject.setBranchContractedIcon(RIME_BRANCH_CONTRACTED_ICON);
             branchObject.setBranchExpandedIcon(RIME_BRANCH_EXPANDED_ICON);
             branchObject.setLeafIcon(RIME_BRANCH_LEAF_ICON);
             branchObject.setLeaf(false);
             branchNode.setUserObject(branchObject);
             rootTreeNode.add(branchNode);
             // add some more sub children
             for (int k = 0; k < 2; k++) {
             	System.out.println("teste " + k);
                 DefaultMutableTreeNode subBranchNode = new DefaultMutableTreeNode();
                 IceUserObject subBranchObject = new IceUserObject(subBranchNode);
                 subBranchObject.setText("sub-node-" + i + "-" + k);
                 subBranchObject.setBranchContractedIcon(RIME_BRANCH_CONTRACTED_ICON);
                 subBranchObject.setBranchExpandedIcon(RIME_BRANCH_EXPANDED_ICON);
                 subBranchObject.setLeafIcon(RIME_BRANCH_LEAF_ICON);
                 branchObject.setLeaf(true);
                 subBranchNode.setUserObject(subBranchObject);
                 branchNode.add(subBranchNode);
             }
         }		
 		
 	}
 	
 	public DefaultTreeModel getModel() {
 		return model;
 	}
 	
 }
 


And this is my view:
Code:
 <?xml version='1.0' encoding='UTF-8' ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml"
 	xmlns:ui="http://java.sun.com/jsf/facelets"
 	xmlns:f="http://java.sun.com/jsf/core"
 	xmlns:h="http://java.sun.com/jsf/html"
 	xmlns:icecore="http://www.icefaces.org/icefaces/core"
     xmlns:ace="http://www.icefaces.org/icefaces/components"
     xmlns:ice="http://www.icesoft.com/icefaces/component"
 	>
 <f:view><h:head>
         <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
         <title>Tree Component Tutorial</title>
         <link href="./resources/css/rime/rime.css" rel="stylesheet" type="text/css" />
         </h:head>    <h:body>        <ice:form>
 
         <!-- first column, for tree navigation -->
         <ice:panelGroup style="border: 1px solid gray; height: 300px;">
             <!--
                 Fully styled Rime themed tree.
             -->
             <ice:tree id="tree" value="#{tree.model}" var="item" hideRootNode="false" hideNavigation="false" imageDir="./resources/css/rime/css-images/">
                 <ice:treeNode>
                     <f:facet name="icon">
                         <ice:panelGroup style="display: inline">
                              <h:graphicImage value="#{item.userObject.icon}"></h:graphicImage>
                         </ice:panelGroup>
                     </f:facet>
                     <f:facet name="content">
                         <ice:panelGroup style="display: inline">
                             <ice:commandLink value="#{item.userObject.text}"></ice:commandLink>
                         </ice:panelGroup>
                     </f:facet>
                 </ice:treeNode>
             </ice:tree>
         </ice:panelGroup>
 
     		</ice:form>	</h:body></f:view>
 </html>
 


And the problem is the same as allanbruno, on the screen is displayed the tree, but the sub-nodes doesn't work...

And thanks for any help!


judy.guglielmin

Joined: 20/Feb/2007 00:00:00
Messages: 1396
Offline


Did you conifigure the compat resource servlet as specified in the documentation on the wiki?
http://wiki.icefaces.org/display/ICE/ICEfaces+Components

I am assuming that you have taken the backing bean and facelet template from the compat component-showcase example.
felipebbarbosa

Joined: 16/Feb/2011 07:12:37
Messages: 4
Offline


It's not possible, I really had not added the jars, but I followed the link that you gave me, and still not working. What am I doing wrong? See my web.xml and my directory structure:

Code:
 ]<?xml version="1.0" encoding="UTF-8"?>
 <web-app version="3.0"
 	xmlns="http://java.sun.com/xml/ns/javaee"
 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"	 
 	xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
 	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
 						http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
   
   <context-param>    
     <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
     <param-value>server</param-value>
   </context-param>
   
   <context-param>
   	<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
   	<param-value>true</param-value>
   </context-param>
   
   <servlet>
     <servlet-name>Faces Servlet</servlet-name>
     <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>    
   </servlet>
   
   <servlet>
   	<servlet-name>Resource Servlet</servlet-name>
   	<servlet-class>com.icesoft.faces.webapp.CompatResourceServlet</servlet-class>
   	<load-on-startup>1</load-on-startup>
   </servlet>
  
   <servlet-mapping>
     <servlet-name>Faces Servlet</servlet-name>
     <url-pattern>*.jsf</url-pattern>
   </servlet-mapping> 
  
   <servlet-mapping>
   	<servlet-name>Resource Servlet</servlet-name>
   	<url-pattern>/xmlhttp/*</url-pattern>
   </servlet-mapping>
   <servlet-mapping>
   	<servlet-name>Faces Servlet</servlet-name>
   	<url-pattern>/icefaces/*</url-pattern>
   </servlet-mapping>  
   
 </web-app>
 


And my structure directory:

Code:
 WebContent
   META-INF
   WEB-INF
     lib
       commons-beanutils.jar
       commons-logging.jar
       icefaces-compat.jar
       icefaces.jar
       jsf-api.jar
       jsf-impl.jar
       jstl-api-1.2.jar
       jstl-impl-1.2.jar
       jxl.jar
       krysalis-jCharts-1.0.0-alpha-1.jar
     faces-config.xml
     web.xml
   teste.xhtml
 







felipebbarbosa

Joined: 16/Feb/2011 07:12:37
Messages: 4
Offline


I'm very beginner and blind. I found the error:

In the second "for" I was setting the leaf true in "branchObject" and not in the "subBranchObject"... Dammit!

judy.guglielmin thanks for helping me...
 
Forum Index -> General Help
Go to:   
Powered by JForum 2.1.7ice © JForum Team