Solved

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

Posted on 2004-04-05
11
222 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Images won't display in JSP pages 30 179
reflection example 3 92
servlet cookie finding by name 1 70
spring example non maven 4 82
There is no doubt that cloud is gaining importance. Many of you must have read about this technology and its growing importance. More and more organisations are embracing this technology not forgetting start-ups. The process begins by dipping …
: Microsoft Office Collaborate for free and online versions of Microsoft  Word, Excel, Powerpoint, OneNote, Onedrive , Email, Calendar etc. In short we can say that Microsoft office is a suite of servers, applications and services developed by  Micr…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 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

23 Experts available now in Live!

Get 1:1 Help Now