public String doSomething() {
bean= new MyBean ();
...
setMyBean(bean); // <--this setter will push the bean to the valuestack.. right???
return SUCCESS;
}
public String doSomething2() {
bean2 = new MyBean2();
...
setMyBean2(bean2);
return SUCCESS;
}
public Object getModel() {
return null; //<-- It returns null because setter() will push the beans to the valuestakc..
}
public void prepare() {
//does nothing..
}
//...getters & setters of MyBean, MyBean2
...
}//end of MyAction
And I try to access to the propery of MyBean class in JSP
Daniele you are not using the ModelDriven correctly. Calling setMyBean or setMyBean2 will not push the objects on the value stack. Actually after the action is finished processing, the whole action class object is added to the value stack. The bean properties of the action can then be used directly (like accessing bean2 calls getBean2 in the action class). ModelDriven is generally used with forms so that form values are automatically set with the property name and the bean name is not required. If you just want to access the properties of the bean without using the bean name, then you can manually push it on the value stack. In the JSP you can use the s:push tag to do this...
Also, please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read. You can edit your post by using the button.
Daniele De Rossi
Greenhorn
Joined: Apr 05, 2010
Posts: 8
posted
0
I figured out how to use ModelDriven exactly by now, sorry.
I had to do like this;
This works well with MyBean class.(Can get access to the property without a class name)
But as I said, two different methods is mapped in struts.xml
==struts.xml==
And each result page tries to do with different beans class.
So, getModel() and prepare() have to work different depends on which method was called.
I mean when doSomething() is called, getModel() and prepare() must do with MyBean class.
And when doSomething2() is called, getModel() and prepare() must do with MyBean2 class.
Is it possible??
This is why I asked you before post, one action must do one task or can do many related tasks.