You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Greg Stasica <gs...@googlemail.com> on 2010/06/29 00:26:20 UTC

Fwd: Model Driven Action doesn't return value when model gets reassigned to some other value - hibernate problem

hi,

the scenario is as follow:1
1. class EditMyBeanAction implements Model...
2. url mapping calls edit method on the EditMyBeanAction
3. the result should be that once edit method returns (it loads MyBean
object from the database) MyBean should be displayed on the jsp

the problem is that it seems like with hibernate it doesn't work at least
when used as below (reassigned object addresses)

classs EditMyBeanAction  implements Model ..<MyBean>

private MyBean bean = new MyBean();

public MyBean getModel()
{
return bean;
}

public String edit()
{
 MyBean mb = hibernateFacade.loadMyBeanObjectById(123);
// bean.setName("test")    ----- 2
bean = mb;    // 3
return "success";

}


i suspect that the problem is somewhere around proxy classes either in
hibernate or ognl (i would rather start to look here though) because if i
uncomment line 2 and comment out 3 i'm getting the test value on the name
property.

surely the workaround is to:
1. copy properties from one object to another but again this is simply a
waste of memory :)
2. get the MyBean object in getModel() method but i don't think this method
should do any dao/business operations

-- 
Greg Stasica



-- 
Greg Stasica

Re: Fwd: Model Driven Action doesn't return value when model gets reassigned to some other value - hibernate problem

Posted by Greg Stasica <gs...@googlemail.com>.
hi,

thanks for your reply but this didn't seem like solve my problem entirely as
PreparableInterceptor gets called before  ParameterInterceptor. The upshot
is that i didn't have an access to my parameters which drive prepare method.
Nevertheless i found that probably the easiest solution here is to
use paramsPrepareParamsStack interceptor. Surely i call some of the
interceptor twice but at least i've an access to the parameters.



On Tue, Jun 29, 2010 at 12:56 PM, Rene Gielen <rg...@apache.org> wrote:

> Hi Greg,
>
> the thing about ModelDriven is that the model object gets pushed on the
> value stack _before_ your action method is executed. To initialize the
> model object before the ModelDrivenInterceptor comes into play, just
> implement Preparable and do your initialization in prepare() (as Lukasz
> already suggested)
>
> - René
>
> Greg Stasica schrieb:
> > hi,
> >
> > the scenario is as follow:1
> > 1. class EditMyBeanAction implements Model...
> > 2. url mapping calls edit method on the EditMyBeanAction
> > 3. the result should be that once edit method returns (it loads MyBean
> > object from the database) MyBean should be displayed on the jsp
> >
> > the problem is that it seems like with hibernate it doesn't work at least
> > when used as below (reassigned object addresses)
> >
> > classs EditMyBeanAction  implements Model ..<MyBean>
> >
> > private MyBean bean = new MyBean();
> >
> > public MyBean getModel()
> > {
> > return bean;
> > }
> >
> > public String edit()
> > {
> >  MyBean mb = hibernateFacade.loadMyBeanObjectById(123);
> > // bean.setName("test")    ----- 2
> > bean = mb;    // 3
> > return "success";
> >
> > }
> >
> >
> > i suspect that the problem is somewhere around proxy classes either in
> > hibernate or ognl (i would rather start to look here though) because if i
> > uncomment line 2 and comment out 3 i'm getting the test value on the name
> > property.
> >
> > surely the workaround is to:
> > 1. copy properties from one object to another but again this is simply a
> > waste of memory :)
> > 2. get the MyBean object in getModel() method but i don't think this
> method
> > should do any dao/business operations
> >
>
> --
> René Gielen
> http://twitter.com/rgielen
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
Greg Stasica

Re: Fwd: Model Driven Action doesn't return value when model gets reassigned to some other value - hibernate problem

Posted by Rene Gielen <rg...@apache.org>.
Hi Greg,

the thing about ModelDriven is that the model object gets pushed on the
value stack _before_ your action method is executed. To initialize the
model object before the ModelDrivenInterceptor comes into play, just
implement Preparable and do your initialization in prepare() (as Lukasz
already suggested)

- René

Greg Stasica schrieb:
> hi,
> 
> the scenario is as follow:1
> 1. class EditMyBeanAction implements Model...
> 2. url mapping calls edit method on the EditMyBeanAction
> 3. the result should be that once edit method returns (it loads MyBean
> object from the database) MyBean should be displayed on the jsp
> 
> the problem is that it seems like with hibernate it doesn't work at least
> when used as below (reassigned object addresses)
> 
> classs EditMyBeanAction  implements Model ..<MyBean>
> 
> private MyBean bean = new MyBean();
> 
> public MyBean getModel()
> {
> return bean;
> }
> 
> public String edit()
> {
>  MyBean mb = hibernateFacade.loadMyBeanObjectById(123);
> // bean.setName("test")    ----- 2
> bean = mb;    // 3
> return "success";
> 
> }
> 
> 
> i suspect that the problem is somewhere around proxy classes either in
> hibernate or ognl (i would rather start to look here though) because if i
> uncomment line 2 and comment out 3 i'm getting the test value on the name
> property.
> 
> surely the workaround is to:
> 1. copy properties from one object to another but again this is simply a
> waste of memory :)
> 2. get the MyBean object in getModel() method but i don't think this method
> should do any dao/business operations
> 

-- 
René Gielen
http://twitter.com/rgielen

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


Re: Model Driven Action doesn't return value when model gets reassigned to some other value - hibernate problem

Posted by Lukasz Lenart <lu...@googlemail.com>.
2010/6/29 Greg Stasica <gs...@googlemail.com>:
> 2. get the MyBean object in getModel() method but i don't think this method
> should do any dao/business operations

You can always use Preparable interface


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/
Kapituła Javarsovia 2010 http://javarsovia.pl

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