0 Replies Latest reply: Dec 16, 2008 12:49 AM by Anil Langote RSS

How to create tree table component using Richfaces , facelet

Anil Langote Newbie

Hi All

I have an requirement where i want to create a componet which is mix of tree and table with tree in the first column of the table. Each cell in the first column of the table has a tree node and each tree node has the row data. I am using JSF 1.2 with facelets 1.1.

Code for reference


<t:tree id="tree" value="#{treeTable.treeModel}" var="treeItem"
 styleClass="tree" nodeClass="treenode" headerClass="treeHeader"
 footerClass="treeFooter" rowClasses="a, b" columnClasses="col1, col2"
 selectedNodeClass="treenodeSelected" expandRoot="true">

<h:column>
 <f:facet name="header">
 <h:outputText value="Header 1" />
 </f:facet>
 <h:outputText value="#{treeItem.isoCode}" />
</h:column>
<t:treeColumn>
 <f:facet name="header">
 <h:outputText value="Header 2" />
 </f:facet>
<h:outputText value="#{treeItem.name}" />
</t:treeColumn>
<h:column>
 <f:facet name="header">
 <h:outputText value="Header 3" />
 </f:facet>
 <h:outputText value="#{treeItem.description}" />

</h:column>
</t:tree>




bean class



public class TreeTableBean implements Serializable
{
 /**
 * serial id for serialisation versioning
 */
 private static final long serialVersionUID = 1L;

 private DefaultTreeModel treeModel;

 /**
 * @param treeModel The treeModel.
 */
 public TreeTableBean(DefaultTreeModel treeModel)
 {
 this.treeModel = treeModel;
 }

 /**
 * <p>
 * Default constructor.
 * </p>
 */
 public TreeTableBean()
 {
 DefaultMutableTreeNode root = new DefaultMutableTreeNode(new TreeItem(1, "XY", "9001", "XY 9001"));
 DefaultMutableTreeNode a = new DefaultMutableTreeNode(new TreeItem(2, "A", "9001", "A 9001"));
 root.insert(a);
 DefaultMutableTreeNode b = new DefaultMutableTreeNode(new TreeItem(3, "B", "9001", "B 9001"));
 root.insert(b);
 DefaultMutableTreeNode c = new DefaultMutableTreeNode(new TreeItem(4, "C", "9001", "C 9001"));
 root.insert(c);

 DefaultMutableTreeNode node = new DefaultMutableTreeNode(new TreeItem(5, "a1", "9002", "a1 9002"));
 a.insert(node);
 node = new DefaultMutableTreeNode(new TreeItem(6, "a2", "9002", "a2 9002"));
 a.insert(node);
 node = new DefaultMutableTreeNode(new TreeItem(7, "a3", "9002", "a3 9002"));
 a.insert(node);
 node = new DefaultMutableTreeNode(new TreeItem(8, "b", "9002", "b 9002"));
 b.insert(node);

 a = node;
 node = new DefaultMutableTreeNode(new TreeItem(9, "x1", "9003", "x1 9003"));
 a.insert(node);
 node = new DefaultMutableTreeNode(new TreeItem(9, "x2", "9003", "x2 9003"));
 a.insert(node);

 this.treeModel = new DefaultTreeModel(root);
 }

 /**
 * @return Returns the treeModel.
 */
 public DefaultTreeModel getTreeModel()
 {
 return treeModel;
 }

 /**
 * @param treeModel The treeModel to set.
 */
 public void setTreeModel(DefaultTreeModel treeModel)
 {
 this.treeModel = treeModel;
 }
}


VO is

public class TreeItem implements Serializable
{
 /**
 * serial id for serialisation versioning
 */
 private static final long serialVersionUID = 1L;

 private int id;

 private String name;

 private String isoCode;

 private String description;


 /**
 * @param id The id.
 * @param name The name.
 * @param isoCode The isoCode.
 * @param description The description.
 */
 public TreeItem(int id, String name, String isoCode, String description)
 {
 this.id = id;
 this.name = name;
 this.isoCode = isoCode;
 this.description = description;
 }

 /**
 * @return Returns the description.
 */
 public String getDescription()
 {
 return description;
 }

 /**
 * @param description The description to set.
 */
 public void setDescription(String description)
 {
 this.description = description;
 }

 /**
 * @return Returns the id.
 */
 public int getId()
 {
 return id;
 }

 /**
 * @param id The id to set.
 */
 public void setId(int id)
 {
 this.id = id;
 }

 /**
 * @return Returns the isoCode.
 */
 public String getIsoCode()
 {
 return isoCode;
 }

 /**
 * @param isoCode The isoCode to set.
 */
 public void setIsoCode(String isoCode)
 {
 this.isoCode = isoCode;
 }

 /**
 * @return Returns the name.
 */
 public String getName()
 {
 return name;
 }

 /**
 * @param name The name to set.
 */
 public void setName(String name)
 {
 this.name = name;
 }
}


i am getting the exception while rendering the page

java.lang.NoClassDefFoundError: javax/servlet/jsp/tagext/JspIdConsumer
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1812)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:866)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1319)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1198)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1812)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:866)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1319)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1198)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at org.apache.myfaces.custom.tree.taglib.TreeTagHandler.setAttributes(TreeTagHandler.java:68)

Please help me how to get rid of this problem i am using richfaces 3.2.1, tomohawk 1.1.7, JSF 1.2 , facelets 1.1.14 and tomcat 5.5 .

BTW : If i copy the javax.servlet.jsp.jar into classpath nothing is working its breaking my application. Please help me.

Thanks
Anil