DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://issues.apache.org/bugzilla/show_bug.cgi?id=28017>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=28017 xsp: generating a XSP computed attribute does not work for ROOT element Summary: xsp: generating a XSP computed attribute does not work for ROOT element Product: Cocoon 2 Version: 2.1.4 Platform: PC OS/Version: Windows XP Status: NEW Severity: Normal Priority: Other Component: core AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] 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">
