Solved

Need Syntax help on converting JSP - <a> tag into a Java function?

Posted on 2004-04-05
11
219 Views
Last Modified: 2010-04-01
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.getName()+"</a>"%>'/>

            resultBuffer.append("<tree:addNode code='<%="<a href=\\"http://www.yahoo.com\\">"
            resultBuffer.append(thisNode.getName());
            resultBuffer.append("</a>"%>'/>");

        } else {
            //print without link
            resultBuffer.append("<tree:addNode code='");
            resultBuffer.append(thisNode.getName());
            resultBuffer.append("'>");
        }



And here is the JSP syntax that is working on the JSP :

<tree:addNode code="<%=gChildNode.getName() %>">
<%
synchronized (gChildNode) {
      final Enumeration hChildren = gChildNode.children();

while (hChildren.hasMoreElements())
{
     final Node hChildNode = (Node)(hChildren.nextElement());
%>
<%-- this  a tag works fine  --%>
<tree:addNode code='<%="<a href=\\"http://www.yahoo.com\\">"+hChildNode.getName()+"</a>"%>'/>




- Awaiting a response

THanks
0
Comment
Question by:sdesar
11 Comments
 
LVL 14

Expert Comment

by:kennethxu
ID: 10760092
use single \ instead of double \\
>> resultBuffer.append("<tree:addNode code='<%="<a href=\\"http://www.yahoo.com\\">"
resultBuffer.append("<tree:addNode code='<%="<a href=\"http://www.yahoo.com\">"
0
 
LVL 5

Expert Comment

by:KarcOrigin
ID: 10763571
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.getName()+"</a>\"");


Kindly reply back. I hope it helps you.
Thx

0
 

Author Comment

by:sdesar
ID: 10768253
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(thisNode.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.getName()+"</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(resultBuffer);


Thanks all for advise

Awaiting a response
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 10768420
the <% thing won't work as a sting in the function. can you post the full code
0
 

Author Comment

by:sdesar
ID: 10768463
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(SystemFolderNode.class);
        filter.reject(SystemFileNode.class);
        filter.reject(HistoryContainerNode.class);
        filter.reject(DeletedItemsFolderNode.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.getName()+"</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(resultBuffer);

        } else {
            //print without link
             System.out.println("else loop");
            resultBuffer.append("<tree:addNode code='");
            resultBuffer.append("+ thisNode.getName()");
            resultBuffer.append("'>");
          //  System.out.println(resultBuffer);
        }

        synchronized (thisNode) {
            try {

                if ((thisNode.getChildCount() > 1) && (level < maxLevel)) {
                    final Enumeration thisNodeChildren = thisNode.children();

                    while (thisNodeChildren.hasMoreElements()) {
                        final Node thisNodeChild = (Node)(thisNodeChildren.nextElement());

                          System.out.println("I am in synchronized recurseNode");
                        if ((thisNodeChild instanceof DbNode) && (filter.accept(thisNode))) {

                            resultBuffer.append(recurseNode((DbNode)thisNodeChild, level+1));
                        }  // end inner if
                    }  // end while
                }  // end outer if
                 System.out.println("end tag");
           //     resultBuffer.append("</tree:addNode>");
                 System.out.println(resultBuffer);
                return resultBuffer.toString();
            } catch (CommandFailedException cfe) {
                Log.write(cfe);
                return null;
            }
        }  // synchronized

    }  // end recurseNode

0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:sdesar
ID: 10776134
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.getProject(session);
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('comments').

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(resultBuffer);

        } else {
            //print without link
             System.out.println("else loop");
            resultBuffer.append("<tree:addNode code='");
            resultBuffer.append("+ thisNode.getName()");
            resultBuffer.append("'>");
          //  System.out.println(resultBuffer);
        }


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!
0
 

Author Comment

by:sdesar
ID: 10779242
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/Catalina/localhost/browseit/org/apache/jsp/GetTree_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(SystemFolderNode.class);
        filter.reject(SystemFileNode.class);
        filter.reject(HistoryContainerNode.class);
        filter.reject(DeletedItemsFolderNode.class);
         // DbNode dbnode=(DbNode)thisNode.findNode(path);
        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.getName()+"</a>"%>'/>

            System.out.println("if loop");
           resultBuffer.append("<tree:addNode code='<%=\"<a href=http://www.yahoo.com\">");
           try {
                resultBuffer.append(thisNode.getName());
           } catch (CommandFailedException cfe) {
                Log.write(cfe);
           }
           resultBuffer.append("</a>%>'/>");
            System.out.println(resultBuffer);
        } else {
            //print without link
             System.out.println("else loop");
            resultBuffer.append("<tree:addNode code='");
            try {
                resultBuffer.append(thisNode.getName());
            } catch (CommandFailedException cfe) {
                Log.write(cfe);
            }

            resultBuffer.append("'>");
            System.out.println(resultBuffer);
        }
        synchronized (thisNode) {
            try {
                if ((thisNode.getChildCount() > 1) && (level < maxLevel)) {
                    final Enumeration thisNodeChildren = thisNode.children();
                    while (thisNodeChildren.hasMoreElements()) {
                        final Node thisNodeChild = (Node)(thisNodeChildren.nextElement());
                          System.out.println("I am in synchronized recurseNode");
                        if ((thisNodeChild instanceof DbNode) && (filter.accept(thisNode))) {
                            resultBuffer.append(recurseNode((DbNode)thisNodeChild, level+1));
                        }  // end inner if
                    }  // end while
                }  // end outer if
                 System.out.println("end tag");
               resultBuffer.append("</tree:addNode>");
           //      System.out.println(resultBuffer);
                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.getProject(session);
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
0
 

Author Comment

by:sdesar
ID: 10785170
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...
0
 

Author Comment

by:sdesar
ID: 11051584
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.getName();

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.
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 11075256
PAQed, with points refunded (100)

Computer101
E-E Admin
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
password protect pdf 11 72
constuctor calling other constructor 2 74
java cyclic graphs 15 194
lessBy10  challenge 15 89
Owning a franchise can be the dream of a lifetime. It provides a chance for economic growth. You can be as successful as you want.  To make your franchise successful, you need to market it successfully. Here are six of the best marketing strategies …
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now