You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Zack Angelo <za...@nostromocorp.com> on 2002/05/03 00:43:48 UTC

xsp-session:get-attribute not returning a String?

Hey, 

I have a statement along the lines of this in my XSP doc:  
	
String test = <xsp-session:get-attribute name="mySessionAttr"/>;

However, it won't work (I get an incompatible types compiler error)
unless I cast it as a String. Consequently, I think it's returning an
invalid value.  The same circumstances apply when I use
session.getAttribute() as well. Any ideas? Thanks in advance. 

-Zack



---------------------------------------------------------------------
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: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>


RE: xsp-session:get-attribute not returning a String?

Posted by Vadim Gritsenko <va...@verizon.net>.
> From: Zack Angelo [mailto:zack@nostromocorp.com]
> 
> Hey,
> 
> I have a statement along the lines of this in my XSP doc:
> 
> String test = <xsp-session:get-attribute name="mySessionAttr"/>;
> 
> However, it won't work (I get an incompatible types compiler error)
> unless I cast it as a String. Consequently, I think it's returning an
> invalid value.  The same circumstances apply when I use
> session.getAttribute() as well. Any ideas? Thanks in advance.

See
http://xml.apache.org/cocoon/apidocs/org/apache/cocoon/environment/Reque
st.html#getAttribute(java.lang.String):

public java.lang.Object getAttribute(java.lang.String name)


http://xml.apache.org/cocoon/apidocs/org/apache/cocoon/environment/Sessi
on.html#getAttribute(java.lang.String):

public java.lang.Object getAttribute(java.lang.String name)


Which means that attributes are *objects*, not strings, and compiler is
right. However, xsp-request logicsheet provides you with conversion
abilities:

<xsp:logic>
String s = <xsp-request:get-attribute name="name" as="string"/>;
Object o = <xsp-request:get-attribute name="name" as="object"/>;
</xsp:logic>
<!--
  Generates XML tag
  <xsp-request:attribute>attr value here</xsp-request:attribute>
-->
<xsp-request:get-attribute name="name" as="xml"/>


Same holds true for session attributes.

Vadim

> -Zack



---------------------------------------------------------------------
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: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>