I strongly encourage you to try all your ideas and to look at the generated
java file...
It's the best way to see what really happens.
Anyway, here are my personal feelings (I work with C1)... But I'm not a
cocoon guru yet :) (the code will tell you the all truth!)


> -----Message d'origine-----
> De : Zeljko Rajic [mailto:[EMAIL PROTECTED]]
> Envoyé : jeudi 12 juillet 2001 13:56
> À : [EMAIL PROTECTED]
> Objet : How to set session attribute correctly
> 
> 
> Hi Cocoon users,
> 
> I'm wondering how to set a session attribute correctly using the
> <xsp-session:set-attribute> tag.
> 
> For example I create an instance of an own object:
> 
> <xsp:logic>
>    MyObject theInstance = new MyObject();
> </xsp:logic>
> 
> 
> Later in the XSP document I'd like to add this instance to 
> the session using
> the <xsp-session:set-attribute> tag. Now I'm not sure what's 
> the correct way
> to do so as there are several possibilites:
> 
> <xsp-session:set-attribute 
> name="MyAttribute">theInstance</xsp-session:set-attribute>

creates a text node containing "theInstance", not what you want

> or:
> 
> <xsp-session:set-attribute 
> name="MyAttribute"><xsp:expr>theInstance</xsp:expr></xsp-sessi
> on:set-attribute>

good

> And then, how to I correctly set a string value? Like this:
> 
> <xsp-session:set-attribute name="MyAttribute">Some text 
> !!</xsp-session:set-attribute>
> 
> or is this the correct way:
> 
> <xsp-session:set-attribute name="MyAttribute"><xsp:content>Some text
> !!</xsp:content></xsp-session:set-attribute>

session variables contain Object... look at the code to see what really
happens

> And by the way, is this kind of expression allowed:
> 
> <xsp-session:set-attribute name="MyAttribute">
>    <xsp:logic>
>       if ( "object".equals(<xsp-request:get-parameter 
> name="MyParam"/>)
>       {
>          <xsp:expr>theInstance</xsp:expr>
>       }
>       else
>       {
>           <xsp:content>Some Text !!</xsp:content>
>       }
>    </xsp:logic>
> </xsp-session:set-attribute>

yes, it should work, but I don't see why you put theInstance inside
xsp:expr...
Everything in xsp:logic is treated as code, except when you use xsp:content

> Any kind of comments are welcome !!
> 
> -  Zeljko
> 
> 
> PS: Yes I know, I could simply use the 
> 'session.setAttribute(...)' method, but
> I'd like to use the <xsp-session:set-attribute> tag.

good idea, I do it myself :)
Olivier

---------------------------------------------------------------------
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