cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robby.pelss...@vodafone.com
Subject RE: problem generating computed attribute for root tag
Date Mon, 29 Mar 2004 13:06:42 GMT
Try something like this
 
<?xml version="1.0" encoding="UTF-8"?>

<xsp:page xmlns:xsp="http://apache.org/xsp"

xmlns:xsp-request="http://apache.org/xsp/request/2.0"

xmlns:esql="http://apache.org/cocoon/SQL/v2"

xmlns:xsp-session="http://apache.org/xsp/session/2.0"

xmlns:i18n="http://apache.org/cocoon/i18n/2.1"

create-session="true">

 

    <dum2>

        <xsp:logic> 

            s = (String)(request.getParameter("test"));

        </xsp:logic>

        <xsp:attribute name="key"><xsp:expr>s</xsp:expr></xsp:attribute>

    </dum2>

    <xsp:logic>

        private String s;

    </xsp:logic>

</xsp:page>

 

-----Original Message-----
From: Wouter.DERUYCK@cec.eu.int [mailto:Wouter.DERUYCK@cec.eu.int]
Sent: 29mm2004 14:42
To: users@cocoon.apache.org
Subject: XSP: problem generating computed attribute for root tag


I have experienced some problems generating xml with some computed
attributes in the root element.

If I try to execute this:

<?xml version="1.0" encoding="UTF-8"?>

<xsp:page xmlns:xsp="http://apache.org/xsp"

xmlns:xsp-request="http://apache.org/xsp/request/2.0"

xmlns:esql="http://apache.org/cocoon/SQL/v2"

xmlns:xsp-session="http://apache.org/xsp/session/2.0"

xmlns:i18n="http://apache.org/cocoon/i18n/2.1"

create-session="true">

 

<!-- this is working fine -->

<xsp:logic>

String dummy = "aaa";

String s = (String)(request.getParameter("test"));

</xsp:logic>

<dum2>

<xsp:attribute name="key"><xsp:expr>s</xsp:expr>

</xsp:attribute>

</dum2>

</xsp:page>

Execution result is an error because if you look at generated code, the
request String object is generated as a class attibute and can't be
initialize because the request object is null. 

:

 

Internal Server Error

Message: Language Exception

Description: org.apache.cocoon.ProcessingException: Language Exception:
org.apache.cocoon.components.language.LanguageException: Error while
instantiating org\apache\cocoon\www\dummy_xsp:
java.lang.NullPointerException

Sender: org.apache.cocoon.servlet.CocoonServlet

Source: Cocoon Servlet

Request URI

dummy/bb

cause

java.lang.NullPointerException

request-uri

/cocoon/dummy/bb

full exception chain stacktrace

Original Exception: org.apache.cocoon.components.language.LanguageException:
Error while instantiating org\apache\cocoon\www\dummy_xsp:
java.lang.NullPointerException



 

Second try:

Then I thought about moving the logic code after the root tag, and hoped my
logic being moved in the generate method:

<?xml version="1.0" encoding="UTF-8"?>

<xsp:page xmlns:xsp="http://apache.org/xsp"

xmlns:xsp-request="http://apache.org/xsp/request/2.0"

xmlns:esql="http://apache.org/cocoon/SQL/v2"

xmlns:xsp-session="http://apache.org/xsp/session/2.0"

xmlns:i18n="http://apache.org/cocoon/i18n/2.1"

create-session="true">

 

<!-- this is working fine -->

 

<dum2>

<xsp:logic>

String dummy = "aaa";

String s = (String)(request.getParameter("test"));

</xsp:logic>

<xsp:attribute name="key"><xsp:expr>s</xsp:expr>

</xsp:attribute>

</dum2>

</xsp:page>

 

 

This failed with a compilig error:

 

Internal Server Error

Message: Language Exception

Description: org.apache.cocoon.ProcessingException: Language Exception:
org.apache.cocoon.components.language.LanguageException: Error compiling
dummy_xsp: ERROR 1 (org\apache\cocoon\www\dummy_xsp.java): ... "", "key",
"key", "CDATA", // start error (lines 298-298) "s cannot be resolved"
String.valueOf(s) + " " // end error ); this.contentHandler.startElement(
... Line 298, column 0: s cannot be resolved

Sender: org.apache.cocoon.servlet.CocoonServlet

Source: Cocoon Servlet

Request URI

dummy/bb

cause

org.apache.cocoon.components.language.LanguageException: Error compiling
dummy_xsp:

ERROR 1 (org\apache\cocoon\www\dummy_xsp.java):

...

"",

"key",

"key",

"CDATA",

// start error (lines 298-298) "s cannot be resolved"

String.valueOf(s) + " "

// end error

);



this.contentHandler.startElement(

...

Line 298, column 0: s cannot be resolved

 

This is because the generation of the attibute 

xspAttr.addAttribute(

"",

"key",

"key",

"CDATA",

String.valueOf(s) + " "

);

is done after the declaration of the s variable!!!

If I move the code a little bit forward in the attribute tag I also
experienced that problem.

The only "turnaround" I found is putting an "artificial" root element like
here under and remove it afterword but it causes other troubles

in my following treatments: 

 

 

<?xml version="1.0" encoding="UTF-8"?>

<xsp:page xmlns:xsp="http://apache.org/xsp"

xmlns:xsp-request="http://apache.org/xsp/request/2.0"

xmlns:esql="http://apache.org/cocoon/SQL/v2"

xmlns:xsp-session="http://apache.org/xsp/session/2.0"

xmlns:i18n="http://apache.org/cocoon/i18n/2.1"

create-session="true">




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


Mime
View raw message