cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robin Green" <gree...@hotmail.com>
Subject Re: Getting started using Beans/XSL
Date Sat, 09 Sep 2000 20:21:40 GMT
Michael Nachbaur <MNachba@rei.com> wrote:
>I'm new to Java, but not programming.  What I want to do is call a javabean 
>from inside my XSL (or XSP) file, and display the results of a method call 
>in the resulting HTML.  In particular, for my current example I'm working 
>on, I'm making a bean that makes a directory listing, then passes those 
>filenames to the XSL file which then makes links out of them (I want to 
>have a dynamic directory listing).
>
>Now, I know how to write that in Java, but where do I stick the resulting 
>.class file when I'm done?

Anywhere you like.

>  And how do I call it from an XSP page?  Can I?

Yes.

1. Add the directory which contains your class, or your classes root package 
if it is in a package, to your CLASSPATH. (you probably need to restart your 
servlet engine to get it to pick up this change).

2. This step is only needed if your class is in a package, and you don't 
want to have to type in mypackage.mysubpackage.myclass repeatedly, but 
instead would like to just type myclass: Put this before your page root 
element, but inside your xsp:page element:

<xsp:structure>
  <xsp:include>mypackage.myclass</xsp:include>
</xsp:structure>

3. Call your class inside your page root element.

<xsp:logic>
  // Just normal Java code goes here
  MyClass x = new MyClass ();
  x.myMethod ();
  // ... etc

and to insert results into the output for them to be matched by XSLT:

<file><xsp:expr>myobj.getFile ();</xsp:expr></file>

I'd personally advise you NOT to base your XSP on the clean-page.xml sample, 
as this uses a deprecated technique and is confusing for the first-time 
Cocooner (it was very confusing to me!)


_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

Share information about yourself, create your own public profile at 
http://profiles.msn.com.


Mime
View raw message