Well I found 2 ways to assign an action's property to a JSP variable in a
scriptlet:
Solution 1: Set property as an attribute
JSP:
<s:set scope="request" var="prodType" value="productType"/>
<%
String myProductType = request.getAttribute("prodType")
%>
This takes the action's productType property and stores it as an attribute
called prodType in the request scope. Then in the scriptlet I get
attribute and assign it to my variable.
Solution 2: Access the action object and call the getter method directly:
JSP:
<%
com.opensymphony.xwork2.ognl.OgnlValueStack stack =
(com.opensymphony.xwork2.ognl.OgnlValueStack)request.getAttribute("struts.valueStack");
ProducTypeAction action = (ProductTypeAction)stack.findValue("action");
String myProductType = action.getProductType();
%>
If oneone has a more elegant solution could you post it.
Thanks.
Graham
On Thu, June 25, 2009 2:00 pm, [email protected] wrote:
>
> Does anyone know how to assign a value from <s:property> to a JSP
> variable?
>
> I'm trying to do something like this (I know this doesn't work):
>
>
> <%
> String prodType = <s:property value="productType"/>;
> %>
>
>
> We're migrating a struts 1.0.2 app to 2.1 and we have a lot of code that
> used to access the ActionForm and assign values to JSP.
>
> Thanks in advance,
> Graham
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]