It`s not really related to seam, but you have discussed other components, so 
I`ll give it a try. I got tree2 working niceley, but now I wan`t to add feature 
'expand/collapse All'. Tomahawk has it allready abled, through HtmlTree 
component. But I do not seem to get tree2 binding to it. It throws 
nullpointerexception when hitting expandAll action.
Have tried everything, hope that you can help me.

  | package ee.digizone.ejb;
  | 
  | import java.io.Serializable;
  | 
  | import java.util.Collections;
  | import java.util.Comparator;
  | 
  | import java.util.List;
  | 
  | import javax.ejb.Remove;
  | import javax.ejb.Stateful;
  | import javax.faces.application.FacesMessage;
  | import javax.faces.component.UIComponent;
  | import javax.faces.context.FacesContext;
  | import javax.faces.event.ActionEvent;
  | import javax.faces.validator.ValidatorException;
  | import javax.persistence.EntityManager;
  | import org.jboss.logging.Logger;
  | 
  | import org.apache.myfaces.custom.tree2.HtmlTree;
  | import org.apache.myfaces.custom.tree2.TreeModel;
  | import org.apache.myfaces.custom.tree2.TreeModelBase;
  | import org.apache.myfaces.custom.tree2.TreeNode;
  | import org.apache.myfaces.custom.tree2.TreeNodeBase;
  | 
  | import org.jboss.seam.annotations.*;
  | import org.jboss.seam.ScopeType;
  | 
  | import ee.digizone.entity.Category;
  | import ee.digizone.entity.Product;
  | 
  | 
  | @Stateful
  | @Name("productList")
  | @Scope(ScopeType.EVENT)
  | public class ProductListBean implements ProductList, Serializable
  | {
  |    
  |     private static final long serialVersionUID = 1L;
  |     Logger logger = Logger.getLogger(ProductListBean.class);
  |     private HtmlTree _tree  = new HtmlTree();
  |     private TreeNode treeData;
  |     
  |     @In(create=true,value="digizoneDatabase")
  |     private EntityManager em; 
  | 
  |     @Create
  |     public void loadData() {
  |             TreeNodeBase tempData = new TreeNodeBase("group", "Root","0", 
false);
  |             List<Category> categories = em.createQuery("from Category c 
where c.head != c.id and c.head = 1 order by c.name").getResultList();
  |             recursive(categories,tempData);
  |             treeData = tempData;
  |             
  |     }
  |     private void recursive(List<Category> categories, TreeNode node) {
  |             sort(categories);
  |             for (Category c: categories) {
  |              TreeNodeBase newNode =  new 
TreeNodeBase("group",c.getName(),String.valueOf(c.getId()), 
c.getGroups().isEmpty() && c.getProducts().isEmpty());
  |              node.getChildren().add( newNode );
  |              List<Product> products = c.getProducts();
  |              sortp(products);
  |              for (Product p: products) 
  |               newNode.getChildren().add(new 
TreeNodeBase("product",p.getName(),String.valueOf(p.getId()), true));    
  |          if (!c.getGroups().isEmpty()) 
  |            recursive(c.getGroups(),newNode);        
  |             }
  |     }
  |     public void sort(List data)
  |     {
  |         Collections.sort(data, new Comparator<Category>() {
  |              public int compare(Category x, Category y)
  |              {
  |                            return 
x.getName().toLowerCase().compareTo(y.getName().toLowerCase());
  |              }
  |           });
  |     }   
  |     public void sortp(List data)
  |     {
  |         Collections.sort(data, new Comparator<Product>() {
  |              public int compare(Product x, Product y)
  |              {
  |                            return 
x.getName().toLowerCase().compareTo(y.getName().toLowerCase());
  |              }
  |           });
  |     } 
  |  
  |        public TreeNode getTreeData()
  |         {
  |             return treeData;
  |         }
  |         
  |         public TreeModel getExpandedTreeData()
  |         {
  |             return new TreeModelBase(getTreeData());
  |         }
  | 
  |         public void setTree(HtmlTree tree)
  |         {
  |             _tree = tree;
  |         }
  | 
  |         public HtmlTree getTree()
  |         {
  |             return _tree;
  |         }
  | 
  |         public String expandAll()
  |         {/*
  |             if (_tree != null)
  |             _tree.expandAll();
  |             else
  |                     logger.info("NULL RAIBE");
  |         */
  |             return null;
  | 
  |         }
  | 
  |         private String _nodePath;
  | 
  |         public void setNodePath(String nodePath)
  |         {
  |             _nodePath = nodePath;
  |         }
  | 
  |         public String getNodePath()
  |         {
  |             return _nodePath;
  |         }
  | 
  |         public void checkPath(FacesContext context, UIComponent component, 
java.lang.Object value)
  |         {
  |             FacesMessage message = null;
  | 
  |             String[] path = _tree.getPathInformation(value.toString());
  | 
  |             for (int i = 0; i < path.length; i++)
  |             {
  |                 String nodeId = path;
  |                 try
  |                 {
  |                     _tree.setNodeId(nodeId);
  |                 }
  |                 catch (Exception e)
  |                 {
  |                     throw new ValidatorException(message, e);
  |                 }
  | 
  |                 if (_tree.getNode().isLeaf())
  |                 {
  |                     message = new FacesMessage(FacesMessage.SEVERITY_ERROR, 
"Invalid node path (cannot expand a leaf): "
  |                             + nodeId, "Invalid node path (cannot expand a 
leaf): " + nodeId);
  |                     throw new ValidatorException(message);
  |                 }
  |             }
  |         }
  | 
  |         public void expandPath(ActionEvent event)
  |         {
  |             _tree.expandPath(_tree.getPathInformation(_nodePath));
  |         }
  | 
  |     @Destroy @Remove
  |     public void destroy() 
  |     {
  |     }
  | }   
  | 
  |     <div class="form2">
  |     <h:form id="foo">
  |     
  |     <h:commandLink action="#{productList.expandAll}"><h:outputText 
value="Tootepuu"/></h:commandLink>
  |     <div class="separator"></div>
  |     <t:tree2 id="categoryTree" binding="#{productList.tree}" 
value="#{productList.treeData}" var="node" varNodeToggler="t" 
clientSideToggle="false" showRootNode="false" showNav="false" showLines="false">
  |         <f:facet name="group">
  |            <h:panelGroup>   
  |                     <span class="tree_bg">
  |                 <h:commandLink immediate="true" 
action="#{t.toggleExpanded}" rendered="#{!empty node.children}">
  |                     <t:graphicImage value="images/arrow_r.gif" 
rendered="#{!t.nodeExpanded}" />
  |                     <t:graphicImage value="images/arrow_d.gif" 
rendered="#{t.nodeExpanded}" />   
  |                 </h:commandLink>
  |                     <h:outputText value="#{node.description}" 
rendered="#{!empty node.children}"/>
  |                             <h:outputText 
value="&#160;&#160;&#160;&#160;&#160;&#160;"/>
  |                     <h:outputText value="#{node.description}" 
rendered="#{empty node.children}"/>
  |                             </span>                 
  |                             <span class="tree_btn">
  |                 <s:link  view="/haldus/cproduct.xhtml" 
action="#{productEditor.selectCreate}">
  |                     <f:param name="catid" value="#{node.identifier}"/>
  |                     <t:graphicImage value="images/tree_add.gif"/>
  |                 </s:link>
  |                 </span>     
  |             </h:panelGroup>
  |         </f:facet>
  |         <f:facet name="product">
  |             <h:panelGroup>
  |                     <span class="tree_bg">
  |                             <h:outputText 
value="&#160;&#160;&#160;&#160;&#160;&#160;"/>
  |                             <s:link view="/haldus/mproduct.xhtml" 
action="#{productEditor.selectModify}">
  |                     <h:outputText value="#{node.description}"/>
  |                     <f:param name="productid" value="#{node.identifier}"/>
  |                 </s:link>
  |                 </span>
  |                 <span class="tree_btn">
  |                 <s:link propagation="begin" 
action="#{productEditor.delete}">
  |                     <f:param name="productid" value="#{node.identifier}"/>
  |                     <t:graphicImage value="images/tree_del.gif"/>
  |                 </s:link>
  |                     </span>
  |             </h:panelGroup>
  |         </f:facet>
  |     </t:tree2>
  |     </h:form>
  |     </div>

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3948137#3948137

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3948137


-------------------------------------------------------
All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to