You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Thorsten Scherler <th...@apache.org> on 2003/05/07 22:39:30 UTC

[Summary] Re: AW: custom java method within XSP

Marco Rolappe wrote:
> hi thorsten,
> 
> the <xsp:logic> element defining the method must be a direct child of the
> <xsp:page> element, just like the <xsp:structure> element. in your case the
> <xsp:logic> is transformed to code within the generator's generate() method
> assuming it will contribute to generation. this of course doesn't work in
> this case; your code fragment is supposed to be part of the class
> definition, not the generate() method.
> 
> HTH

Thank you very much Marco!

Solution:
<xsp:logic> element defining the method must be a direct child of the 
<xsp:page> element

My Case (Problem):
<xsp:page language="java" xmlns:xsp="http://apache.org/xsp">
<list>->This custom element was not allowed here!
<xsp:logic>

Explanation:
The <xsp:page/> element has two different parts. One part where you can 
put your class definition (1) and the other part is within the 
generator's generate() method (2). (1) has to be a direct child of 
<xsp:page/>. (2) starts a soon you use a custom element (<list>). Java 
method has to be declared in (1) and can then be used in (2).

example.xsp:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsp:page language="java" xmlns:xsp="http://apache.org/xsp">
<xsp:logic>
  private static String getParameter(String input)
   {
     if(input == null || input.equals(""))
       return "The parameter you have been requested is NULL or ''";
     else return input;
   }
</xsp:logic>

   <page>
<p>Parameter: 
<xsp:expr>getParameter(request.getParameter("STREET"))</xsp:expr></p>
   </page>

</xsp:page>

if you want to test it with your cocoon-app, save the example.xsp and 
call it LIKE (you have to modify your sitemap.xmap)
1) http://localhost:8080/YOURAPP/example.xsp?STREET=
2) http://localhost:8080/YOURAPP/example.xsp?STREET=test

> 
> 
>>-----Ursprüngliche Nachricht-----
>>Von: cocoon-users-return-50236-m_rolappe=web.de@xml.apache.org
>>[mailto:cocoon-users-return-50236-m_rolappe=web.de@xml.apache.org]Im
>>Auftrag von Scherler, Thorsten
>>Gesendet: Dienstag, 6. Mai 2003 17:12
>>An: Cocoon-Users (E-Mail)
>>Betreff: custom java method within XSP
>>
>>
>>Hello group,
>>
>>I would like to use a Java method within my xsp. It is not working!
>>
>>Code:
>><xsp:page language="java" xmlns:xsp="http://apache.org/xsp"
>>xmlns:esql="http://apache.org/cocoon/SQL/v2"
>>xmlns:xsp-request="http://apache.org/xsp/request/2.0">
>>	<xsp:structure>
>>		<xsp:include>java.util.*</xsp:include>
>>		<xsp:include>java.text.*</xsp:include>
>>	</xsp:structure><!-- -->
>><list>
>><xsp:logic>
>> private static String getParameter(String input)
>>  {
>>    if(input == null || input.equals(""))
>>      return "";
>>    else return input;
>>  }
>></xsp:logic>
>><p>
>>test
>></p>
>></list>
>></xsp:page>
>>
>>Error:
>>org.apache.cocoon.ProcessingException: Language Exception:
>>org.apache.cocoon.components.language.LanguageException: Error
>>compiling update_all_xsp: Line 287, column 1: illegal start of
>>expression Line 0, column 0: 1 error
>>
>>Using:
>>cocoon 2.04
>>
>>
>>>Mit freundlichem Gruss,
>>>
>>>Thorsten Scherler
>>>Marketing / Telefonmarketing
>>>
>>>Weidmüller GmbH & Co.
>>>P.O. Box 2807
>>>33058 Paderborn
>>>Tel.:+ 49 - 5252-960-350
>>>Fax:+ 49 - 5252-960-116
>>>eMail: thorsten.scherler@weidmueller.de
>>>http://www.weidmueller.de
>>>
>>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
>>For additional commands, e-mail: cocoon-users-help@xml.apache.org
>>



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