You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Asleson, Ryan" <as...@BIWORLDWIDE.com> on 2008/04/29 17:47:13 UTC

Accessing the Struts2 Action in a JSP via tags

 
Hello,
 
I'm new to Struts 2.
 
Assume that I'm on a JSP that has been rendered with a Struts2 Action.
Somehow I want to access the Action and its properties via a JSP tag,
something like this:
 
<c:out value="${action.myValue}" />
 
What is the correct way to do this?  Is the Struts 2 Action placed on
the request using a specific name, or is it available via OGNL?  If so,
how do I access it?
 
Thank you!!
 
-Ryan
 
 

This e-mail message is being sent solely for use by the intended recipient(s) and may contain confidential information.  Any unauthorized review, use, disclosure or distribution is prohibited.  If you are not the intended recipient, please contact the sender by phone or reply by e-mail, delete the original message and destroy all copies. Thank you.

RE: Accessing the Struts2 Action in a JSP via tags

Posted by Dave Newton <ne...@yahoo.com>.
--- "Asleson, Ryan" <as...@BIWORLDWIDE.com> wrote:
> OK, so by just using:
> 
> ${myValue} 
> 
> The myValue property of the Action class will be accessed?  I suppose
> this works as long as there aren't other "myName" properties in the
> other scopes, right?

The request wrapper searches the JSP contexts first; it goes to the stack
context iff nothing can be found. So yes, if a context contains an object
with the same name it'll find that one "first".

> I take it that Struts2 essentially exposes the action as another scope
> to JSP EL?

Sort of, in the sense that it'll get searched after the normal context-based
lookup fails.

Dave


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Accessing the Struts2 Action in a JSP via tags

Posted by "Asleson, Ryan" <as...@BIWORLDWIDE.com>.
OK, so by just using:

${myValue} 

The myValue property of the Action class will be accessed?  I suppose
this works as long as there aren't other "myName" properties in the
other scopes, right?

I take it that Struts2 essentially exposes the action as another scope
to JSP EL?

Thank you!

-----Original Message-----
From: Dave Newton [mailto:newton.dave@yahoo.com] 
Sent: Tuesday, April 29, 2008 11:05 AM
To: Struts Users Mailing List
Subject: Re: Accessing the Struts2 Action in a JSP via tags

--- "Asleson, Ryan" <as...@BIWORLDWIDE.com> wrote:
> Assume that I'm on a JSP that has been rendered with a Struts2 Action.
> Somehow I want to access the Action and its properties via a JSP tag, 
> something like this:
>  
> <c:out value="${action.myValue}" />
>  
> What is the correct way to do this?  Is the Struts 2 Action placed on 
> the request using a specific name, or is it available via OGNL?  If 
> so, how do I access it?

Short answer: 

${myValue}

Long answer:

The S2 request wrapper provides a way for JSP EL to access stack context
objects. You can also use the S2 property tag.

<s:property value="myValue"/>

Dave


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


This e-mail message is being sent solely for use by the intended recipient(s) and may contain confidential information.  Any unauthorized review, use, disclosure or distribution is prohibited.  If you are not the intended recipient, please contact the sender by phone or reply by e-mail, delete the original message and destroy all copies. Thank you.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Accessing the Struts2 Action in a JSP via tags

Posted by Dave Newton <ne...@yahoo.com>.
--- "Asleson, Ryan" <as...@BIWORLDWIDE.com> wrote:
> Assume that I'm on a JSP that has been rendered with a Struts2 Action.
> Somehow I want to access the Action and its properties via a JSP tag,
> something like this:
>  
> <c:out value="${action.myValue}" />
>  
> What is the correct way to do this?  Is the Struts 2 Action placed on
> the request using a specific name, or is it available via OGNL?  If so,
> how do I access it?

Short answer: 

${myValue}

Long answer:

The S2 request wrapper provides a way for JSP EL to access stack context
objects. You can also use the S2 property tag.

<s:property value="myValue"/>

Dave


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org