You can have functions in XSP.
Just put them in a CDATA section, in a logic tag, between include and page.

Ed

<xsp:page>
    <xsp:include>java.util.*</xsp:include>
    <xsp:logic>
    <![CDATA[
        private boolean isValid(Vector vector, String s)
        {
            return true;
        }
    ]]>
    </xsp:logic>
    <page>
    </page>
</xsp:page>

---

From: "Nicola Ken Barozzi" <[EMAIL PROTECTED]>
Reply-To: "Nicola Ken Barozzi" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Subject: Re: Having a function in a XSP.
Date: Tue, 19 Feb 2002 09:11:06 +0100

From: "Olivier Rossel" <[EMAIL PROTECTED]>

 > Supposing I repeat the same XSP fragment several times in my XSP page.
 > And I wish to "factorize" that with a function which receives
 > parameters,  and
 > is a kind of "XSP" fragment.
 > Is it possible?

Taglibs have this role, to become libraries of commonly used xsp fragments.
But they are not functions, they behave similarly to macros AFAIK.

Taglibs are basically stylesheets that are applied to your XSP before it
gets compiled. This means that you cannot use taglibs as functions that
recieve live data; you can call taglibs only with predefined parameters. A
common way is to use attributes.

What can be done, is passing code fragments, so that the taglib uses those
to get live data.
I think that call-template can help you in calling taglibs with parameters.

A simple way of doing taglibs is to transform your xsp with your taglib
using Xalan and checking that the resulting file is the xsp that you want;
it's the xsp that gets compiled.

 > Can I create an inner class with methods inside a XSP?

Don't think so. All XSP code goes in the resulting Generator's generate()
method. What you should do IMHO is to use helper classes.

For more information on taglibs, I suggest you to look at the cocoon builtin
taglibs in the sourcecode.

--
Nicola Ken Barozzi                 [EMAIL PROTECTED]
             - verba volant, scripta manent -
    (discussions get forgotten, just code remains)
---------------------------------------------------------------------


---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <[EMAIL PROTECTED]>
For additional commands, e-mail: <[EMAIL PROTECTED]>


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.


---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <[EMAIL PROTECTED]>
For additional commands, e-mail: <[EMAIL PROTECTED]>

Reply via email to