[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2004-04-05
11
Medium Priority
?
248 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

With the evolution of technology, we have finally reached a point where it is possible to have home automation features like having your thermostat turn up and door lock itself when you leave, as well as a complete home security system. This is a st…
What monsters are hiding in your child's room? In this article I will share with you a tech horror story that could happen to anyone, along with some tips on how you can prevent it from happening to you.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

656 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