sdesar
asked on
Need Syntax help on converting JSP - <a> tag into a Java function?
Hello,
I have a JSP page that displays treeview using a tree tag lib.
I need to recursively call this tree view so I am placing it in the JAVA recurseNode function.
The error that I have is
JSPProperties.java:220: illegal character
when I am doing :-
resultBuffer.append("<tree :addNode code='<%="<a href=\\"http://www.yahoo.com\\">"
the entire resultBuffer.append string.
Would you please help me with the syntax ?
here is the Java syntax in the function recurseNode that is NOT working ( **I need your help to fix it)-
//print out <tree with link ** I get a illegal character error .. on these lines
// <tree:addNode code='<%="<a href=\\"http://www.yahoo.com\\">"+hChildNode.get Name()+"</ a>"%>'/>
resultBuffer.append("<tree :addNode code='<%="<a href=\\"http://www.yahoo.com\\">"
resultBuffer.append(thisNo de.getName ());
resultBuffer.append("</a>" %>'/>");
} else {
//print without link
resultBuffer.append("<tree :addNode code='");
resultBuffer.append(thisNo de.getName ());
resultBuffer.append("'>");
}
And here is the JSP syntax that is working on the JSP :
<tree:addNode code="<%=gChildNode.getNam e() %>">
<%
synchronized (gChildNode) {
final Enumeration hChildren = gChildNode.children();
while (hChildren.hasMoreElements ())
{
final Node hChildNode = (Node)(hChildren.nextEleme nt());
%>
<%-- this a tag works fine --%>
<tree:addNode code='<%="<a href=\\"http://www.yahoo.com\\">"+hChildNode.get Name()+"</ a>"%>'/>
- Awaiting a response
THanks
I have a JSP page that displays treeview using a tree tag lib.
I need to recursively call this tree view so I am placing it in the JAVA recurseNode function.
The error that I have is
JSPProperties.java:220: illegal character
when I am doing :-
resultBuffer.append("<tree
the entire resultBuffer.append string.
Would you please help me with the syntax ?
here is the Java syntax in the function recurseNode that is NOT working ( **I need your help to fix it)-
//print out <tree with link ** I get a illegal character error .. on these lines
// <tree:addNode code='<%="<a href=\\"http://www.yahoo.com\\">"+hChildNode.get
resultBuffer.append("<tree
resultBuffer.append(thisNo
resultBuffer.append("</a>"
} else {
//print without link
resultBuffer.append("<tree
resultBuffer.append(thisNo
resultBuffer.append("'>");
}
And here is the JSP syntax that is working on the JSP :
<tree:addNode code="<%=gChildNode.getNam
<%
synchronized (gChildNode) {
final Enumeration hChildren = gChildNode.children();
while (hChildren.hasMoreElements
{
final Node hChildNode = (Node)(hChildren.nextEleme
%>
<%-- this a tag works fine --%>
<tree:addNode code='<%="<a href=\\"http://www.yahoo.com\\">"+hChildNode.get
- Awaiting a response
THanks
Hi,
I am not sure what string you are expecting at the end from yours StringBuffer object but I think that the contactination of the string is not correct. Could you please send us the resulted string which you want? In any case try this -
resultBuffer.append("<tree :addNode code=\"<a href='http://www.yahoo.com'>"+hChildNode.getNam e()+"</a>\ "");
Kindly reply back. I hope it helps you.
Thx
I am not sure what string you are expecting at the end from yours StringBuffer object but I think that the contactination of the string is not correct. Could you please send us the resulted string which you want? In any case try this -
resultBuffer.append("<tree
Kindly reply back. I hope it helps you.
Thx
ASKER
When the code runs thisNode.getName() gets passed as a string, I need it to output some value like 'employee' etc...
I tired to pass it as resultBuffer.append("+ thisNode.getName()"); // does not work
or
resultBuffer.append(thisNo de.getName ()); // does not work
BTW - seems like just one '/' works but I won't know for sure until I see the JSP running...
Here is the code below--
// in JSP the tree tag looks like the comment below
//<tree:addNode code='<%="<a href=\\"http://www.yahoo.com\\">"+hChildNode.get Name()+"</ a>"%>'/>
System.out.println("if loop");
resultBuffer.append("<tree :addNode code='<%=\"<a href=http://www.yahoo.com\">");
resultBuffer.append("thisN ode.getNam e()");
resultBuffer.append("</a>% >'/>");
// System.out.println(resultB uffer);
Thanks all for advise
Awaiting a response
I tired to pass it as resultBuffer.append("+ thisNode.getName()"); // does not work
or
resultBuffer.append(thisNo
BTW - seems like just one '/' works but I won't know for sure until I see the JSP running...
Here is the code below--
// in JSP the tree tag looks like the comment below
//<tree:addNode code='<%="<a href=\\"http://www.yahoo.com\\">"+hChildNode.get
System.out.println("if loop");
resultBuffer.append("<tree
resultBuffer.append("thisN
resultBuffer.append("</a>%
// System.out.println(resultB
Thanks all for advise
Awaiting a response
the <% thing won't work as a sting in the function. can you post the full code
ASKER
Here is the code
public String recurseNode(DbNode thisNode, int level) {
// level = 0;
final int maxLevel = 4;
final StringBuffer resultBuffer = new StringBuffer();
final NodeClassFilter filter = new NodeClassFilter();
filter.accept(DefaultNode. class);
filter.reject(SystemFolder Node.class );
filter.reject(SystemFileNo de.class);
filter.reject(HistoryConta inerNode.c lass);
filter.reject(DeletedItems FolderNode .class);
System.out.println("I am in recurseNode");
//DO STUFF HERE
if (level == maxLevel) {
//print out <tree with link
// in JSP the tree tag looks like the comment below
//<tree:addNode code='<%="<a href=\\"http://www.yahoo.com\\">"+hChildNode.get Name()+"</ a>"%>'/>
System.out.println("if loop");
resultBuffer.append("<tree :addNode code='<%=\"<a href=http://www.yahoo.com\">");
resultBuffer.append("+ thisNode.getName()");
resultBuffer.append("</a>% >'/>");
// System.out.println(resultB uffer);
} else {
//print without link
System.out.println("else loop");
resultBuffer.append("<tree :addNode code='");
resultBuffer.append("+ thisNode.getName()");
resultBuffer.append("'>");
// System.out.println(resultB uffer);
}
synchronized (thisNode) {
try {
if ((thisNode.getChildCount() > 1) && (level < maxLevel)) {
final Enumeration thisNodeChildren = thisNode.children();
while (thisNodeChildren.hasMoreE lements()) {
final Node thisNodeChild = (Node)(thisNodeChildren.ne xtElement( ));
System.out.println("I am in synchronized recurseNode");
if ((thisNodeChild instanceof DbNode) && (filter.accept(thisNode))) {
resultBuffer.append(recurs eNode((DbN ode)thisNo deChild, level+1));
} // end inner if
} // end while
} // end outer if
System.out.println("end tag");
// resultBuffer.append("</tre e:addNode> ");
System.out.println(resultB uffer);
return resultBuffer.toString();
} catch (CommandFailedException cfe) {
Log.write(cfe);
return null;
}
} // synchronized
} // end recurseNode
public String recurseNode(DbNode thisNode, int level) {
// level = 0;
final int maxLevel = 4;
final StringBuffer resultBuffer = new StringBuffer();
final NodeClassFilter filter = new NodeClassFilter();
filter.accept(DefaultNode.
filter.reject(SystemFolder
filter.reject(SystemFileNo
filter.reject(HistoryConta
filter.reject(DeletedItems
System.out.println("I am in recurseNode");
//DO STUFF HERE
if (level == maxLevel) {
//print out <tree with link
// in JSP the tree tag looks like the comment below
//<tree:addNode code='<%="<a href=\\"http://www.yahoo.com\\">"+hChildNode.get
System.out.println("if loop");
resultBuffer.append("<tree
resultBuffer.append("+ thisNode.getName()");
resultBuffer.append("</a>%
// System.out.println(resultB
} else {
//print without link
System.out.println("else loop");
resultBuffer.append("<tree
resultBuffer.append("+ thisNode.getName()");
resultBuffer.append("'>");
// System.out.println(resultB
}
synchronized (thisNode) {
try {
if ((thisNode.getChildCount()
final Enumeration thisNodeChildren = thisNode.children();
while (thisNodeChildren.hasMoreE
final Node thisNodeChild = (Node)(thisNodeChildren.ne
System.out.println("I am in synchronized recurseNode");
if ((thisNodeChild instanceof DbNode) && (filter.accept(thisNode)))
resultBuffer.append(recurs
} // end inner if
} // end while
} // end outer if
System.out.println("end tag");
// resultBuffer.append("</tre
System.out.println(resultB
return resultBuffer.toString();
} catch (CommandFailedException cfe) {
Log.write(cfe);
return null;
}
} // synchronized
} // end recurseNode
ASKER
This is how I call the function in the JSP -
GetTree.jsp
------------
<%@ page import = "src.abtest.*"
%>
<%@ taglib uri="taglib_tree.tld" prefix="tree" %>
<%
ProjectNode projectNode=null;
projectNode= BmxServletUtilities.getPro ject(sessi on);
JSPProperties JP = new JSPProperties();
%>
<a href="http://www"> hello </a>
<tree:createTree treePicture="tree.gif" nodePicture="leaf.gif" openPicture="open.gif" dhtml="true">
<% JP.recurseNode(projectNode , 0); %>
</tree:createTree>
The JSP calls the recurseNode and I see it running in the logs with the System.out.println('commen ts').
But I don't see any output in the JSP.
I suspect its this code that is not working correctly since the syntax is not right -
System.out.println("if loop");
resultBuffer.append("<tree :addNode code='<%=\"<a href=http://www.yahoo.com\">");
resultBuffer.append("+ thisNode.getName()");
resultBuffer.append("</a>% >'/>");
// System.out.println(resultB uffer);
} else {
//print without link
System.out.println("else loop");
resultBuffer.append("<tree :addNode code='");
resultBuffer.append("+ thisNode.getName()");
resultBuffer.append("'>");
// System.out.println(resultB uffer);
}
The logs just diplay the data like this -
I am in recurseNode
if loop
<tree:addNode code='<%="<a
href=http://www.yahoo.com">thisNode.getName()< /a>%>'/>
I am in synchronized recurseNode
I am in synchronized recurseNode
I am in synchronized recurseNode
I am in synchronized recurseNode
I am in recurseNode
I am in synchronized recurseNode
I am in recurseNode
I am in synchronized recurseNode
I am in recurseNode
I am in synchronized recurseNode
I am in recurseNode
if loop
<tree:addNode code='<%="<a
href=http://www.yahoo.com">thisNode.getName()< /a>%>'/>
Thanks for helping -
Awaitng a response!
GetTree.jsp
------------
<%@ page import = "src.abtest.*"
%>
<%@ taglib uri="taglib_tree.tld" prefix="tree" %>
<%
ProjectNode projectNode=null;
projectNode= BmxServletUtilities.getPro
JSPProperties JP = new JSPProperties();
%>
<a href="http://www"> hello </a>
<tree:createTree treePicture="tree.gif" nodePicture="leaf.gif" openPicture="open.gif" dhtml="true">
<% JP.recurseNode(projectNode
</tree:createTree>
The JSP calls the recurseNode and I see it running in the logs with the System.out.println('commen
But I don't see any output in the JSP.
I suspect its this code that is not working correctly since the syntax is not right -
System.out.println("if loop");
resultBuffer.append("<tree
resultBuffer.append("+ thisNode.getName()");
resultBuffer.append("</a>%
// System.out.println(resultB
} else {
//print without link
System.out.println("else loop");
resultBuffer.append("<tree
resultBuffer.append("+ thisNode.getName()");
resultBuffer.append("'>");
// System.out.println(resultB
}
The logs just diplay the data like this -
I am in recurseNode
if loop
<tree:addNode code='<%="<a
href=http://www.yahoo.com">thisNode.getName()<
I am in synchronized recurseNode
I am in synchronized recurseNode
I am in synchronized recurseNode
I am in synchronized recurseNode
I am in recurseNode
I am in synchronized recurseNode
I am in recurseNode
I am in synchronized recurseNode
I am in recurseNode
I am in synchronized recurseNode
I am in recurseNode
if loop
<tree:addNode code='<%="<a
href=http://www.yahoo.com">thisNode.getName()<
Thanks for helping -
Awaitng a response!
ASKER
I think I am pretty close /.. I see the data in the LOGS BUT NO data in the HTML/JSP Page.. Eargerly awaiting a reponse..
Thanks for your advise.
I implemented your suggestions.
I don't see the data in HTML/JSP page.
However, when I view the logs all the data is being displayed in the logs.
Awaiting Suggestions!
In the JSP I tried to add -
<%= JP.recurseNode(projectNode , 0) %>
or
<% JP.recurseNode(projectNode , 0); %>
Both of these output to the logs and NOT to the web browser.
This line
<%= JP.recurseNode(projectNode , 0); %> // with the semicolon produces an error
/usr/local/tomcat/jakarta- tomcat-5.0 .18-abrain /work/Cata lina/local host/brows eit/org/ap ache/jsp/G etTree_jsp .java:91: ')' expected
out.print( JP.recurseNode(projectNode , 0); );
// JSPProperties.java
public String recurseNode(DbNode thisNode, int level) {
final int maxLevel = 4;
final StringBuffer resultBuffer = new StringBuffer();
final NodeClassFilter filter = new NodeClassFilter();
filter.accept(DefaultNode. class);
filter.reject(SystemFolder Node.class );
filter.reject(SystemFileNo de.class);
filter.reject(HistoryConta inerNode.c lass);
filter.reject(DeletedItems FolderNode .class);
// DbNode dbnode=(DbNode)thisNode.fi ndNode(pat h);
System.out.println("I am in recurseNode");
// System.out.println("Node is: " + thisNode.getDisplayName()) ;
//DO STUFF HERE
if (level == maxLevel) {
//print out <tree with link
// in JSP the tree tag looks like the comment below
//<tree:addNode code='<%="<a href=\\"http://www.yahoo.com\\">"+hChildNode.get Name()+"</ a>"%>'/>
System.out.println("if loop");
resultBuffer.append("<tree :addNode code='<%=\"<a href=http://www.yahoo.com\">");
try {
resultBuffer.append(thisNo de.getName ());
} catch (CommandFailedException cfe) {
Log.write(cfe);
}
resultBuffer.append("</a>% >'/>");
System.out.println(resultB uffer);
} else {
//print without link
System.out.println("else loop");
resultBuffer.append("<tree :addNode code='");
try {
resultBuffer.append(thisNo de.getName ());
} catch (CommandFailedException cfe) {
Log.write(cfe);
}
resultBuffer.append("'>");
System.out.println(resultB uffer);
}
synchronized (thisNode) {
try {
if ((thisNode.getChildCount() > 1) && (level < maxLevel)) {
final Enumeration thisNodeChildren = thisNode.children();
while (thisNodeChildren.hasMoreE lements()) {
final Node thisNodeChild = (Node)(thisNodeChildren.ne xtElement( ));
System.out.println("I am in synchronized recurseNode");
if ((thisNodeChild instanceof DbNode) && (filter.accept(thisNode))) {
resultBuffer.append(recurs eNode((DbN ode)thisNo deChild, level+1));
} // end inner if
} // end while
} // end outer if
System.out.println("end tag");
resultBuffer.append("</tre e:addNode> ");
// System.out.println(resultB uffer);
return resultBuffer.toString();
} catch (CommandFailedException cfe) {
net.common.Log.write(cfe);
return null;
}
} // synchronized
} // end recurseNode
//GetTree.jsp
<%@ page import = "src.abtest.*"
import="java.util.*"
%>
<%@ taglib uri="taglib_tree.tld" prefix="tree" %>
<%
ProjectNode projectNode=null;
projectNode= BmxServletUtilities.getPro ject(sessi on);
JSPProperties JP = new JSPProperties();
%>
<a href="http://www"> hello </a>
<tree:createTree treePicture="tree.gif" nodePicture="leaf.gif" openPicture="open.gif" dhtml="true">
<%= JP.recurseNode(projectNode , 0) %>
</tree:createTree>
//Snippet of the LOGS =
I am in synchronized recurseNode
end tag
I am in synchronized recurseNode
I am in recurseNode
else loop
<tree:addNode code='beths_garage'>
I am in synchronized recurseNode
I am in recurseNode
if loop
<tree:addNode code='<%="<a href=http://www.yahoo.com">locations143-ld.jpg </a>%>'/>
end tag
I am in synchronized recurseNode
I am in recurseNode
if loop
<tree:addNode code='<%="<a href=http://www.yahoo.com">locations24-rgh-ld. jpg</a>%>' />
end tag
Thanks for your advise.
I implemented your suggestions.
I don't see the data in HTML/JSP page.
However, when I view the logs all the data is being displayed in the logs.
Awaiting Suggestions!
In the JSP I tried to add -
<%= JP.recurseNode(projectNode
or
<% JP.recurseNode(projectNode
Both of these output to the logs and NOT to the web browser.
This line
<%= JP.recurseNode(projectNode
/usr/local/tomcat/jakarta-
out.print( JP.recurseNode(projectNode
// JSPProperties.java
public String recurseNode(DbNode thisNode, int level) {
final int maxLevel = 4;
final StringBuffer resultBuffer = new StringBuffer();
final NodeClassFilter filter = new NodeClassFilter();
filter.accept(DefaultNode.
filter.reject(SystemFolder
filter.reject(SystemFileNo
filter.reject(HistoryConta
filter.reject(DeletedItems
// DbNode dbnode=(DbNode)thisNode.fi
System.out.println("I am in recurseNode");
// System.out.println("Node is: " + thisNode.getDisplayName())
//DO STUFF HERE
if (level == maxLevel) {
//print out <tree with link
// in JSP the tree tag looks like the comment below
//<tree:addNode code='<%="<a href=\\"http://www.yahoo.com\\">"+hChildNode.get
System.out.println("if loop");
resultBuffer.append("<tree
try {
resultBuffer.append(thisNo
} catch (CommandFailedException cfe) {
Log.write(cfe);
}
resultBuffer.append("</a>%
System.out.println(resultB
} else {
//print without link
System.out.println("else loop");
resultBuffer.append("<tree
try {
resultBuffer.append(thisNo
} catch (CommandFailedException cfe) {
Log.write(cfe);
}
resultBuffer.append("'>");
System.out.println(resultB
}
synchronized (thisNode) {
try {
if ((thisNode.getChildCount()
final Enumeration thisNodeChildren = thisNode.children();
while (thisNodeChildren.hasMoreE
final Node thisNodeChild = (Node)(thisNodeChildren.ne
System.out.println("I am in synchronized recurseNode");
if ((thisNodeChild instanceof DbNode) && (filter.accept(thisNode)))
resultBuffer.append(recurs
} // end inner if
} // end while
} // end outer if
System.out.println("end tag");
resultBuffer.append("</tre
// System.out.println(resultB
return resultBuffer.toString();
} catch (CommandFailedException cfe) {
net.common.Log.write(cfe);
return null;
}
} // synchronized
} // end recurseNode
//GetTree.jsp
<%@ page import = "src.abtest.*"
import="java.util.*"
%>
<%@ taglib uri="taglib_tree.tld" prefix="tree" %>
<%
ProjectNode projectNode=null;
projectNode= BmxServletUtilities.getPro
JSPProperties JP = new JSPProperties();
%>
<a href="http://www"> hello </a>
<tree:createTree treePicture="tree.gif" nodePicture="leaf.gif" openPicture="open.gif" dhtml="true">
<%= JP.recurseNode(projectNode
</tree:createTree>
//Snippet of the LOGS =
I am in synchronized recurseNode
end tag
I am in synchronized recurseNode
I am in recurseNode
else loop
<tree:addNode code='beths_garage'>
I am in synchronized recurseNode
I am in recurseNode
if loop
<tree:addNode code='<%="<a href=http://www.yahoo.com">locations143-ld.jpg
end tag
I am in synchronized recurseNode
I am in recurseNode
if loop
<tree:addNode code='<%="<a href=http://www.yahoo.com">locations24-rgh-ld.
end tag
ASKER
Please help..
I think all the code is fine .. and I see the data being outputted to catalina.out log file and I want the data to output to JSP .
What is the syntax to tell the JAVA code to output to JSP instead of using resultBuffer.append I need some JSP Writer???
Eagerly awaiting suggeestions...
I think all the code is fine .. and I see the data being outputted to catalina.out log file and I want the data to output to JSP .
What is the syntax to tell the JAVA code to output to JSP instead of using resultBuffer.append I need some JSP Writer???
Eagerly awaiting suggeestions...
ASKER
The suggestions were good, but it did not help me with the treeview taglib I used from http://www.servletsuite.com/
The tree view tag lib accepts a treeBean object, so I had to add a new parameter TreeBean parent
TreeBean node1 = null;
node1 = new TreeBean();
node1.setCode(thisNode.get Name();
And in the JSP
TeeBean root = new TreeBean();
root.setCode("employee");
JP.recurseNode(root, projectNode, 0);
etc...
Sincere thanks for your kind efforts with this question, but since the suggestion did not help answer the question could you please refund the points.
The tree view tag lib accepts a treeBean object, so I had to add a new parameter TreeBean parent
TreeBean node1 = null;
node1 = new TreeBean();
node1.setCode(thisNode.get
And in the JSP
TeeBean root = new TreeBean();
root.setCode("employee");
JP.recurseNode(root, projectNode, 0);
etc...
Sincere thanks for your kind efforts with this question, but since the suggestion did not help answer the question could you please refund the points.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>> resultBuffer.append("<tree
resultBuffer.append("<tree