cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nathaniel Alfred" <Alfred.Nathan...@swx.com>
Subject RE: FOR-loop in xsp:logic section
Date Tue, 17 May 2005 15:19:45 GMT
The content of <xsp:logic> as immediate child of <xsp:page> is inserted
into the class scope and can therefore be used to define private methods
and variables.

For variables one has to be aware that the compiled XSP will be recycled,
and initializations will not be repeated.  A classic error is that

<xsp:page>
  <xsp:structure>
    <xsp:include>java.util.Date</xsp:include>
  </xsp:structure>
  <xsp:logic>
    Date now = new Date();
    String formatDate(Date date) {
      return date.toString();
    }
  </xsp:logic>
  <now>
    <xsp:expr>formatDate(now)</xsp:expr>
  </now>
<xsp:page>

prints the date when the XSP is compiled, and not when it is called.

HTH, Alfred.

-----Original Message-----
From: Michael Milvich [mailto:m.milvich@gmx.de]
Sent: Montag, 16. Mai 2005 18:51
To: users@cocoon.apache.org
Subject: Re: FOR-loop in xsp:logic section


Hallo,

thank you Chris for help. It's working!

I also I looked at the created *.java class and found out that cocoon is 
doing something strange, when the additional elements are missing. Here 
is the code:

 XSPObjectHelper.xspExpr(contentHandler, obj);
      ;
           }
        }
            for (int i=0;i< 9; i++)
            i=i+1;


Is this a bug in cocoon?


regards

Michael Milvich

Chris Maloney wrote:

> Try wrapping your "xsp:logic" in some other element, like this:
>
> <?xml version="1.0" encoding="iso-8859-1"?>
> <xsp:page language="java" xmlns:xsp="http://apache.org/xsp"
>   xmlns:xsp-request="http://apache.org/xsp/request/2.0"
>   xmlns:xsp-session="http://apache.org/xsp/session/2.0"
>   xmlns:esql="http://apache.org/cocoon/SQL/v2"
>   create-session="true">
>   <xsp:structure>
>   </xsp:structure>
>  <OtherElement>
>   <xsp:logic>
>           for (int i=0;i&lt; 9; i++){
>               i=i+1;
>           }
>   </xsp:logic>
>  </OtherElement>
> </xsp:page>
>
> FWIW, it can help in debugging XSP problems to examine the ".java" 
> file that gets created.  I'm using Cocoon 2.1.5.1, and that puts these 
> generated .java files into 
> build/webapp/WEB-INF/work/cocoon-files/org/apache/cocoon/www/....  I 
> think, in later versions, it puts them somewhere else, under a system 
> temp directory.  In your case, search for getStatement_xsp.java (which 
> you can see from the error message, is the name of the .java file).
>
> HTH,
> Chris Maloney
>
>
> Michael Milvich wrote:
>
>> Hallo,
>>
>> i am using Cocoon 2.1.7, jdk 1.4 and tomcat 5.0.19.
>>
>> I would like to include in a xsp-page a small logic part and in this 
>> logic section a FOR loop.
>> Everything works fine, only the FOR loop doesn't work. Here is my 
>> simple code:
>>
>> <?xml version="1.0" encoding="iso-8859-1"?>
>> <xsp:page language="java" xmlns:xsp="http://apache.org/xsp"
>>    xmlns:xsp-request="http://apache.org/xsp/request/2.0"
>>    xmlns:xsp-session="http://apache.org/xsp/session/2.0"
>>    xmlns:esql="http://apache.org/cocoon/SQL/v2"
>>    create-session="true">
>>    <xsp:structure>
>>    </xsp:structure>
>>    <xsp:logic>
>>            for (int i=0;i&lt; 9; i++){
>>                i=i+1;
>>            }
>>    </xsp:logic>
>> </xsp:page>
>>
>> I get the following error when calling the xsp-page:
>>
>>> Error compiling getStatement_xsp: ERROR 1 
>>> (org\apache\cocoon\www\apples\xsp\getStatement_xsp.java): ... 
>>> XSPObjectHelper.xspExpr(contentHandler, obj); ; } // start error 
>>> (lines 237-237) "Syntax error on token "}", { expected after this 
>>> token" } // end error for (int i=0;i< 9; i++) i=i+1; ... ERROR 2 
>>> (org\apache\cocoon\www\apples\xsp\getStatement_xsp.java): ... ; } } 
>>> // start error (lines 239-239) "Syntax error on token(s), misplaced 
>>> construct(s)" for (int i=0;i< 9; i++) // end error i=i+1; /** ... 
>>> Line 237, column 0: Syntax error on token "}", { expected after this 
>>> token Line 239, column 0: Syntax error on token(s), misplaced 
>>> construct(s)
>>
>>
>>
>>
>> My question is. How can I include a FOR or a WHILE loop in the 
>> xsp:logic section?
>>
>> Thanks for help in advance
>>
>> Michael Milvich
>>
>> --------------------------------------------------------------------- 
>> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org For 
>> additional commands, e-mail: users-help@cocoon.apache.org 
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
 
 
This message is for the named person's use only. It may contain confidential, proprietary
or legally privileged information. No confidentiality or privilege is waived or lost by any
mistransmission. If you receive this message in error, please notify the sender urgently and
then immediately delete the message and any copies of it from your system. Please also immediately
destroy any hardcopies of the message. You must not, directly or indirectly, use, disclose,
distribute, print, or copy any part of this message if you are not the intended recipient.
The sender's company reserves the right to monitor all e-mail communications through their
networks. Any views expressed in this message are those of the individual sender, except where
the message states otherwise and the sender is authorised to state them to be the views of
the sender's company.

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


Mime
View raw message