struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Pierre Thibaudeau" <pierre.thibaud...@gmail.com>
Subject Re: [S2] ModelDriven: model not pushed on stack?
Date Wed, 27 Aug 2008 04:18:52 GMT
2008/8/26 Pierre Thibaudeau <pierre.thibaudeau@gmail.com>

> [...] suddenly, on my most recent action, the model does not find its way
> to the top of the stack, and I cannot find where the problem might be.
>

I dug deeper into this issue and found something very surprising. The
strange behaviour centres around the execute() method.  I am very tempted to
call it a severe bug (for Struts 2.1.2)...

To make things simple, I produced a test case (see below):  two very simple
ModelDriven Action classes.  The first one works as expected, and pushes the
Model ("SmallObject") on top of the ValueStack.  The second action
surprisingly fails to push the Model on the stack (though the Model is still
accessible through the Action being on the stack).

In short, it seems that the model is not pushed on the stack when its value
is last assigned inside the execute() method!!!

Am I forgetting something, or is this truly a bug?
It might be worth knowing from others if the same problem occurs with
version of Struts earlier than 2.1.2.

/************/
/* /test.jsp */
/************/
<html><body>
    Model on the stack: ${foo}<br/>
    Action on the stack: ${model.foo}
</body></html>

/************/
/* struts.xml */
/*************/
<struts>
    <package name="default" extends="struts-default" abstract="false"
namespace="/" >
        <default-interceptor-ref name="paramsPrepareParamsStack"/>
        <action name="successfull"
class="com.myapp.SuccessfullAction"><result>/test.jsp</result></action>
        <action name="failing"
class="com.myapp.FailingAction"><result>/test.jsp</result></action>
   </package>
</struts>

/******************/
/* SmallObject.java */
/******************/
public class SmallObject {
    private String foo;
    public String getFoo() { return foo; }
    public SmallObject(String str) { foo = str; }
}

/*******************/
/* SuccessfullAction */
/*******************/
public class SuccessfullAction extends ActionSupport implements
ModelDriven<SmallObject>, Preparable {
    private SmallObject obj;
    public SmallObject getModel() { return obj; }
    public void prepare() { obj = new SmallObject("bar"); }
    public String execute() { return SUCCESS; }
}

/******************/
/* FailingAction */
/******************/
public class FailingAction extends ActionSupport implements
ModelDriven<SmallObject>, Preparable {
    private SmallObject obj;
    public SmallObject getModel() { return obj; }
    public void prepare() { /* do nothing */ }
    public String execute() {
        obj = new SmallObject("bar");
        return SUCCESS;
    }
}

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message