• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem using UI:Tree

 
badri nath
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to work with Tree Structure using JSF UI tags. In Studio Creator i just created a JSP page and designed a Tree with two nodes under it.

This is what i have in the body of my jsp.

<ui:body binding="#{Page1.body1}" id="body1" style="-rave-layout: grid">
<ui:form binding="#{Page1.form1}" id="form1">
<ui:tree binding="#{Page1.tree1}" id="tree1" style="left: 48px; top: 48px; position: absolute" text="L3">
<ui:treeNode binding="#{Page1.treeNode1}" expanded="true" id="treeNode1" style="width: 408px" text="Tree Node 1">
<f:facet name="image">
<ui:image binding="#{Page1.image1}" icon="TREE_DOCUMENT" id="image1"/>
</f:facet>
</ui:treeNode>
<ui:treeNode binding="#{Page1.treeNode2}" expanded="true" id="treeNode2" text="Tree Node 2">
<f:facet name="image">
<ui:image binding="#{Page1.image2}" icon="TREE_DOCUMENT" id="image2"/>
</f:facet>
</ui:treeNode>
</ui:tree>
</ui:form>
</ui:body>

But when i am trying to launch the jsp page from browser i am getting the below exception.

com.sun.rave.web.ui.appbase.ApplicationException
Caused by: java.lang.NullPointerException at java.io.File.(File.java:194) at com.sun.rave.web.ui.renderer.template.xml.XMLLayoutDefinitionManager.getLayoutDefinition(XMLLayoutDefinitionManager.java:142) at com.sun.rave.web.ui.component.TemplateComponentBase.getLayoutDefinition(TemplateComponentBase.java:150) at com.sun.rave.web.ui.renderer.template.TemplateRenderer.encodeBegin(TemplateRenderer.java:73) at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:683)

Any suggestion to solve this issue would be greatly helpful.
 
Darryl Nortje
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what line 194 looks like in java.io.File...

public File(String pathname) {
if (pathname == null) {
throw new NullPointerException(); //LINE 194
}
this.path = fs.normalize(pathname);
this.prefixLength = fs.prefixLength(this.path);
}

So there error is being thrown because you are trying to instantiate a java.io.File object with a null, for the file/path name.

Hope this helps.

cheers
Darryl
 
badri nath
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the response Deryl. But the error is being thrown from the code in webui.jar file. com.sun.rave.web.ui.renderer.template.xml.XMLLayoutDefinitionManager.getLayoutDefinition(XMLLayoutDefinitionManager.java:142

I think the jar file is internally looking for some other file on classpath. To use <ui:tree /> do we need to have anything extra in classpath?

In my jsp page i removed everything from the design and was just keeping <ui:tree id="myTree"/> tag in the body of jsp and even this was throwing the same exception.
 
Darryl Nortje
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey,

Post the full bean, and full jsp code here. I'll see if I can get it running this side.

cheers
Darryl
 
badri nath
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Deryl, I dont know if i can attach files as attachment here in ranch. I have copied the entire jsp and the bean hereunder. Thanks for your efforts you are putting in to help me.

Page1.jsp

----------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<jsp:root version="1.2" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:ui="http://www.sun.com/web/ui" xmlns:xng="com.granite.xng.webtk">
<jsp:directive.page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"/>
<f:view>
<ui:page binding="#{Page1.page1}" id="page1">
<ui:html binding="#{Page1.html1}" id="html1">
<ui:head binding="#{Page1.head1}" id="head1">
<ui:link binding="#{Page1.link1}" id="link1" url="/resources/stylesheet.css"/>
</ui:head>
<ui:body binding="#{Page1.body1}" id="body1" style="-rave-layout: grid">
<ui:form binding="#{Page1.form1}" id="form1">
<ui:tree binding="#{Page1.tree1}" id="tree1" style="left: 48px; top: 48px; position: absolute" text="L3">
<ui:treeNode action="#{Page1.treeNode1_action}" binding="#{Page1.treeNode1}" expanded="true" id="treeNode1" style="width: 408px" text="Tree Node 1">
<f:facet name="image">
<ui:image binding="#{Page1.image1}" icon="TREE_DOCUMENT" id="image1"/>
</f:facet>
</ui:treeNode>
<ui:treeNode binding="#{Page1.treeNode2}" expanded="true" id="treeNode2" text="Tree Node 2">
<f:facet name="image">
<ui:image binding="#{Page1.image2}" icon="TREE_DOCUMENT" id="image2"/>
</f:facet>
</ui:treeNode>
</ui:tree>
</ui:form>
</ui:body>
</ui:html>
</ui:page>
</f:view>
</jsp:root>

----------------------------------

Page1.java

----------------------------------

package webapplication1;

import com.sun.rave.web.ui.appbase.AbstractPageBean;
import com.sun.rave.web.ui.component.Body;
import com.sun.rave.web.ui.component.Form;
import com.sun.rave.web.ui.component.Head;
import com.sun.rave.web.ui.component.Html;
import com.sun.rave.web.ui.component.Link;
import com.sun.rave.web.ui.component.Page;
import javax.faces.FacesException;
import com.sun.rave.web.ui.component.Tree;
import com.sun.rave.web.ui.component.TreeNode;
import com.sun.rave.web.ui.component.ImageComponent;

public class Page1 extends AbstractPageBean {

private int __placeholder;

private void _init() throws Exception {
}

private Page page1 = new Page();

public Page getPage1() {
return page1;
}

public void setPage1(Page p) {
this.page1 = p;
}

private Html html1 = new Html();

public Html getHtml1() {
return html1;
}

public void setHtml1(Html h) {
this.html1 = h;
}

private Head head1 = new Head();

public Head getHead1() {
return head1;
}

public void setHead1(Head h) {
this.head1 = h;
}

private Link link1 = new Link();

public Link getLink1() {
return link1;
}

public void setLink1(Link l) {
this.link1 = l;
}

private Body body1 = new Body();

public Body getBody1() {
return body1;
}

public void setBody1(Body b) {
this.body1 = b;
}

private Form form1 = new Form();

public Form getForm1() {
return form1;
}

public void setForm1(Form f) {
this.form1 = f;
}

private Tree tree1 = new Tree();

public Tree getTree1() {
return tree1;
}

public void setTree1(Tree t) {
this.tree1 = t;
}

private TreeNode treeNode1 = new TreeNode();

public TreeNode getTreeNode1() {
return treeNode1;
}

public void setTreeNode1(TreeNode tn) {
this.treeNode1 = tn;
}

private ImageComponent image1 = new ImageComponent();

public ImageComponent getImage1() {
return image1;
}

public void setImage1(ImageComponent ic) {
this.image1 = ic;
}

private TreeNode treeNode2 = new TreeNode();

public TreeNode getTreeNode2() {
return treeNode2;
}

public void setTreeNode2(TreeNode tn) {
this.treeNode2 = tn;
}

private ImageComponent image2 = new ImageComponent();

public ImageComponent getImage2() {
return image2;
}

public void setImage2(ImageComponent ic) {
this.image2 = ic;
}

public Page1() {
}

protected RequestBean1 getRequestBean1() {
return (RequestBean1)getBean("RequestBean1");
}

protected ApplicationBean1 getApplicationBean1() {
return (ApplicationBean1)getBean("ApplicationBean1");
}

protected SessionBean1 getSessionBean1() {
return (SessionBean1)getBean("SessionBean1");
}

public void init() {
super.init();
try {
_init();
} catch (Exception e) {
log("Page1 Initialization Failure", e);
throw e instanceof FacesException ? (FacesException) e: new FacesException(e);
}
}

public void preprocess() {
}

public void prerender() {
}

public void destroy() {
}


public String treeNode1_action() {
// TODO: Replace with your code

return null;
}
}

-----------------------------------------
 
Darryl Nortje
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yisee Badri,

My simple answer is I can't help you. I don't know this UI stuff that you're using. So hopefully someone else can. However what I can do is show you what I have working here. I am using MyFaces, with some tomahawk components. What I try to do is keep it simple and then go from there, so this is the simplest example hardcoding the tree in the bean, and displaying it's contents on a jsp page.

The Bean:


and now here is the jsp that displays this tree.



Hope this helps.
Cheers
Darryl
 
badri nath
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using Tomahawk is not a problem for me and i successfully tried the example which you have suggested.

Actually i was trying to implement the following requirement. I want to display information in the table in form of Tree Structure. At tree level i have more than one column and same goes with tree nodel level. The data should look some thing like this.

(+)Employer1_Name Employer1_Description
|-Employee1_Salary Employee1_Maritial_Status
|-Employee2_Salary Employee2_Maritial_Status
(+)Employer2_Name Employer2_Description
|-Employee3_Salary Employee3_Maritial_Status
|-Employee4_Salary Employee4_Maritial_Status

And the Employer/Employee related information would be stored in a backing bean.

With Tomahawks Example i saw that we were able to stored only one String at each level. But i want to display data in more than one column at each level.

Folks, can you help me in suggesting a way or with some samples in getting my requirement done.
 
Darryl Nortje
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also thought about that with my examples Badri. Didn't implement it though.

But, this is what I thought you can do, perhaps if you get it working you can post it here. You can extend TreeNodeBase, add your extra information and getters to it, then access that info in the jsp.

Then you can add custom info to each level of the tree. I'll also try get this working here, if you can't do it.

cheers
Darryl
 
badri nath
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks For Solution Deryl. I think i understood what you are trying to say. Let me explain to make myself clear.
I need to create an object which extends TreeNodeBase and add my information to that object. And in my jsp page i need to use this object to display information on JSP.
I would continue my struggle to get this working but as i am a new-bee to JSF can you even try to get this working for me. I will reply back if i can find any success.
 
Darryl Nortje
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
;-) Badri, I am also a newbie.... No worries.

I'll play a little this afternoon and try get back to you then.


cheers
Darryl
 
badri nath
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Deryl and ranchers, can you help me by getting something working for me
 
Darryl Nortje
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Behdri, (<-- excuse the spelling, but I'm just getting you back for messing my name up horribly ;-).

Good news. I got it working. It's pretty easy, and exactly what I mentioned earlier on.

Firstly, I extended TreeNodeBase with a class I called, for lack of a better work, CustomTreeNode. This class overides TreeNodeBase's constructor, and simply calls to super, passing in all the variables.

Then I added 3 of my own methods, getDescription (override TreeNodeBase's getDescription, with your own....) and then I added 2 more, getName and getSalary for example. Then I populated the tree, in the normal way, obviously now just adding the extra information per node.

Then in my Jsp, I define the tree2 component, make it's value a treeModel on my bean, which contains the CustomTreeNode, and bind it to an HtmlTree also on the bean. Then I have my 2 facets, for the "folders" and for the "content" of each folder. Then I simply refer to my custom getters off the node, ie: #{node.name} or #{node.salary}

Bob's your uncle. ;-)


cheers
Darryl
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!