The example you give compiles however if I look at the generated code below,
I see that the code for adding the attribute appears before the
initialization of the String variable s, hence when we execute the code the
attribute key appears as "null". This seems like a bug to me ..
xspAttr.addAttribute(
"",
"key",
"key",
"CDATA",
String.valueOf(s)
);
this.contentHandler.startElement(
"",
"dum2",
"dum2",
xspAttr
);
xspAttr.clear();
this.characters("\n ");
s = (String)(request.getParameter("test"));
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Monday, March 29, 2004 15:07
To: [EMAIL PROTECTED]
Subject: RE: problem generating computed attribute for root tag
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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: 29mm2004 14:42
To: [EMAIL PROTECTED]
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]