cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paint...@mc.duke.edu
Subject Re: Undefined variable or class name: request
Date Fri, 11 May 2001 22:20:01 GMT

Are you at Duke or is our gateway just making it seem that way?

Anyway, look at your generated Java code.  You are using the variable
"request" in your own method, getMac().  The problem is, request isn't
defined in the class, it is only a local variable to the populateDocument()
method.

There are a variety of approaches to do what you want to do.  First, you
can redefine getMac() to take the request object as a parameter, e.g.,
String[] getMac(HttpServletRequest request) { };  Then, as long as your
calls to getMac(request) are within populateDocument(), you'll be fine.

How do things get inside populateDocument()?

Simple XSP (no logicsheet):

   <?xml version="1.0"?>
   <?cocoon-process type="xsp"?>
   <xsp:page
     xmlns:xsp="http://www.apache.org/1999/XSP/Core">
     <xsp:logic>
       <!-- This stuff ends up at the class level, not inside populateDocument() -->
     </xsp:logic>
     <page>
       <xsp:logic>
         <!-- This is inside populateDocument(), you can use request -->
       </xsp:logic>
     </page>
   </xsp:page>

If you are writing a custom logicsheet, then consider this sample logicsheet:

   <?xml version="1.0"?>
   <xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xsp="http://www.apache.org/1999/XSP/Core"
    xmlns:mytags="http://duke.edu/mytags"
    version="1.0"
   >

   <xsl:template match="xsp:page">
     <xsl:copy>
       <xsl:apply-templates select="@*"/>
       <xsp:structure>
       </xsp:structure>
       <xsp:logic>
         <!-- This again ends up at the class level, not inside populateDocument() -->
       </xsp:logic>
       <xsl:apply-templates/>
     </xsl:copy>
   </xsl:template>

   <xsl:template match="xsp:page/*[not(starts-with(name(.), 'xsp:'))]">
    <xsl:copy>
     <xsl:apply-templates select="@*"/>
     <xsp:logic>
       <!-- This ends up inside populateDocument(), after the general XSP -->
       <!-- declarations but before your other matched tags.  Thus, you   -->
       <!-- can use request here, you can also declare and set your own   -->
       <!-- variables and use them in other matched tags.                 -->
     </xsp:logic>
     <xsl:apply-templates/>
    </xsl:copy>
   </xsl:template>

Hope that helps.

-Christopher




Please respond to cocoon-users@xml.apache.org

Sent by:  tsturgeo@balin.mc.duke.edu


To:   "cocoon-users@xml.apache.org" <cocoon-users@xml.apache.org>
cc:

Subject:  Undefined variable or class name: request


At last I get my logicsheet and taglibs running.

The whole reason I went that way was to avoid this problem
---------------------------------------------

Error found handling the request.

                     java.lang.Exception: XSP Java Compiler: Compilation
failed for _process.java
                     26: Undefined variable or class name: request
                             String [] macout =
request.getParameterValues("mac");
                                                ^
                     1 error


                             at
java.lang.Throwable.fillInStackTrace(Native Method)
                             at
java.lang.Throwable.fillInStackTrace(Compiled Code)
                             at java.lang.Throwable.<init>(Compiled
Code)
                             at java.lang.Exception.<init>(Compiled
Code)
                             at
org.apache.cocoon.processor.xsp.language.java.XSPJavaProcessor.compile(Compiled

Code)
                             at
org.apache.cocoon.processor.xsp.XSPProcessor.process(Compiled Code)
                             at org.apache.cocoon.Engine.handle(Compiled
Code)
                             at
org.apache.cocoon.Cocoon.service(Cocoon.java:183)
                             at
javax.servlet.http.HttpServlet.service(HttpServlet.java:588)
                             at
org.apache.jserv.JServConnection.processRequest(JServConnection.java:314)

                             at
org.apache.jserv.JServConnection.run(Compiled Code)
                             at java.lang.Thread.run(Compiled Code)
---------------------------------------------
Here is a fragment from the _process.java file

 public class _process extends XSPPage {
      /* User Class Declarations */

        public String [] getMac(){
        String [] macout = request.getParameterValues("mac");
        return macout;
        }


      public void populateDocument(
        HttpServletRequest request,
        HttpServletResponse response,
        Document document
      )
        throws Exception
      {
        // Node stack logic variables
        Node xspParentNode = null;
        Node xspCurrentNode = document;
        Stack xspNodeStack = new Stack();

So, what is going one here?




---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <cocoon-users-unsubscribe@xml.apache.org>
For additional commands, e-mail: <cocoon-users-help@xml.apache.org>


Mime
View raw message