Dave Newton wrote:
--- On Thu, 12/4/08, Robert Graf-Waczenski wrote:
I'm using Struts 2.0.14, any chance that this is a fixed bug?
If it is unknown, i'll go file a bug then.
I dunno; I've used this pattern on a few apps (ScopedModelDriven, too) so I'm
skeptical it's a bug. Could you post the config for the action that displays
the form and the relevant action code? If I have a chance I'll also do a quick
sanity check test on this end.
OK, here goes:
#######################################
struts.xml
#######################################
<struts>
<package namespace="/blah/blurp" name="com.blah.blurp"
extends="struts-default">
<action name="add" class="com.blah.blurp.actions2.AddAction">
<result name="success"
type="redirect">/JSP/blah/blurp/add.jsp</result>
</action>
</package>
</struts>
#########################################
Simplified AddAction.java:
#########################################
public class AddAction implements ModelDriven<AddAction.SessionValues>,
ServletRequestAware
{
private HttpSession mSession;
private HttpServletRequest mRequest;
private SessionValues mSessionValues;
public void setServletRequest(HttpServletRequest request)
{
mRequest = request;
mSession = mRequest.getSession();
}
public SessionValues getModel()
{
SessionValues sessionValues = (SessionValues)
mSession.getAttribute(SessionValues.NAME);
if (sessionValues == null) {
sessionValues = new SessionValues();
mSession.setAttribute(SessionValues.NAME, sessionValues);
}
mSessionValues = sessionValues;
return sessionValues;
}
public String execute()
{
// stripped code that performs something usefull
mSessionValues.mMessage = "Success!";
return SUCCESS;
}
public static class SessionValues
{
public final static String NAME = "mySessionValues";
private String mAddress;
private String mMessage;
public String getmAddress()
{
return mAddress;
}
public void setmAddress(String v)
{
mAddress = v;
}
public String getmMessage()
{
return mMessage;
}
}
}
###################################################
Simplified add.jsp:
###################################################
<s:form cssStyle="padding:0; margin:0" action="/blah/blurp/add"
theme="simple">
<div class="message" style="padding-bottom:10px">
This works: <s:property value="#session.mySessionValues.mMessage"/>
</div>
<div class="message" style="padding-bottom:10px">
This doesn't work: <s:property value="mMessage"/>
</div>
<div style="padding-top:15px">
<s:submit />
</div>
</s:form>
This should yield the following: The first access to add.jsp should show
"This works:" and "This doesn't work:" both without any message
suffixed. Clicking the button should execute the action once, which
should set the mMessage field of the mSessionValues Action member to
"Success!". This text should be visible after the action has
*redirected* back to add.jsp. What you see is that only the first usage
of s:property works, i.e. is suffixed with "Success!". The second one is
what doesn't work.
If i change the struts.xml to use a dispatcher type result when sending
the user back to the JSP, then both accesses to mMessage work, but this
is not what i want. I'm also aware of *why* it works after dispatching:
The subsequent page access still finds the ValueStack in the request
scope, which it of course doesn't when i'm using a redirect.
I have stripped down the actual code considerably, so if you need
further details, i'll be happy to supply them.
Robert
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]