You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Adam Hardy <ah...@cyberspaceroad.com> on 2008/01/31 16:15:13 UTC

preparable vs modelDriven

Is my understanding correct that Preparable and ModelDriven are 2 different ways 
of doing the same thing, or are they complementary in any way?

After reading up on the website there are a few questions that spring to mind.

* ModelDriven: how do I get hold of my model during my action methods? I don't 
want to get getModel() again, because that will retrieve another instance of the 
entity and not the one that was populated by struts.

* why do param-prepare-param instead of just prepare-param with

ServletActionContext.getRequest().getParameter("id") in prepare,

which would save a whole cycle through the param interceptor?



Regards
Adam

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


Re: preparable vs modelDriven

Posted by Musachy Barroso <mu...@gmail.com>.
you are right.

On Jan 31, 2008 1:12 PM, Roberto Nunnari <ro...@supsi.ch> wrote:
> The prepare() method task is to retrive the model
> and store it as an instance variable.
>
> The getModel() method will later return the model
> when asked by the framework that will put it on the
> value stack.
>
> Please correct me if I'm wrong.
>
> Best regards.
>
> --
> Robi
>
>
>
>
> Adam Hardy wrote:
> > Dave Newton on 31/01/08 16:00, wrote:
> >> Adam Hardy <ah...@cyberspaceroad.com> wrote:
> >>> Dave Newton on 31/01/08 15:29, wrote:
> >>>> Adam Hardy <ah...@cyberspaceroad.com> wrote:
> >>>>> * ModelDriven: how do I get hold of my model during my action
> >>>>> methods? I
> >>>>> don't  want to get getModel() again, because that will retrieve
> >>>>> another
> >>>>> instance of the  entity and not the one that was populated by struts.
> >>>> Lazy initialization (via null check or by setting an instance var), or
> >>>> config through Spring, or...
> >>> If your getModel() puts the model entity on an instance variable, won't
> >>> that confuse the param interceptor?
> >>
> >> Depends on what instance variable you put it in, I suppose. One of your
> >> questions was how to access the model object w/o running through a
> >> getModel()
> >> method that would re-instantiate; lazily initializing an instance
> >> variable in
> >> getModel() then using that instance variable is one way of dealing
> >> with that.
> >
> > OK, that makes sense now, thanks. What I thought would be the more
> > obvious way of obtaining the model would be to fetch it from where
> > struts puts it when it calls getModel(), i.e. the value stack, however I
> > don't see any access methods for doing that, particulary on ActionSupport.
> >
> >
> > Adam
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

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


Re: preparable vs modelDriven

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
I thought I'd quickly describe my usages and opinions of Preparable and 
ModelDriven in case it helps any one:

- As Dave described, I also prefer to keep my prepare logic with the 
main code because it's easier for others to understand.
- I do use Preparable in the cases where params-prepare-params is 
desirable: typically where the params are directly addressing a nested 
bean and the parent needs to be initialised/loaded by id first.  I avoid 
this but its valuable in those occasional cases.
 - When using ModelDriven, putting any logic inside getModel() is a bad 
idea.  This is akin to putting logic inside getters.  The model is 
always an instance variable.
 - My interpretation of the primary objective of ModelDriven is to put 
the model object at the top of the value stack rather than the action.  
Therefore it is complementary with Preparable
 - My use of ModelDriven is also rare because it can make the context of 
a JSP/FTL  harder to understand (eg. I prefer contact.firstName rather 
than firstName).  However it has proven extremely useful in some cases, 
particularly if the model is polymorphic (same action, different result, 
different model class)

cheers,
Jeromy Evans

Musachy Barroso wrote:
> Struts will by default populate parameters in your action, if you use
> ModelDriven, then you can supply the object that will be populated
> instead of the action. Implementing preparable will make struts call
> prepare() before the action is executed, or prepareX() before X() is
> executed. They are just sometimes used together to achieve certain
> things, as explained on the other emails.
>
> musachy
>
> On Jan 31, 2008 5:03 PM, Adam Hardy <ah...@cyberspaceroad.com> wrote:
>   
>> I don't think you are strictly conveying the intended usage, when you say that
>> the getModel() method will 'later' return the model. It depends how your
>> interceptor stack is ordered. In the docs, it explicitly says the
>> ModelDrivenInterceptor should come before ParametersInterceptor, as often the
>> PrepareInterceptor does.
>>
>> Both ModelDriven- and PrepareInterceptor can retrieve the model and place it in
>> instance variables on the action.
>>
>> http://struts.apache.org/2.0.11/docs/prepare-interceptor.html
>>
>> http://struts.apache.org/2.0.11/docs/model-driven-interceptor.html
>>
>> What I originally wanted to ask (whether I conveyed my question correctly is
>> another matter) was: what's the difference in intention and implementation
>> between these two?
>>
>> Thanks
>> Adam
>>
>> Roberto Nunnari on 31/01/08 18:12, wrote:
>>     
>>> The prepare() method task is to retrive the model
>>> and store it as an instance variable.
>>>
>>> The getModel() method will later return the model
>>> when asked by the framework that will put it on the
>>> value stack.
>>>
>>> Please correct me if I'm wrong.
>>>
>>>       
>>> Adam Hardy wrote:
>>>       
>>>> Dave Newton on 31/01/08 16:00, wrote:
>>>>         
>>>>> Adam Hardy <ah...@cyberspaceroad.com> wrote:
>>>>>           
>>>>>> Dave Newton on 31/01/08 15:29, wrote:
>>>>>>             
>>>>>>> Adam Hardy <ah...@cyberspaceroad.com> wrote:
>>>>>>>               
>>>>>>>> * ModelDriven: how do I get hold of my model during my action
>>>>>>>> methods? I
>>>>>>>> don't  want to get getModel() again, because that will retrieve
>>>>>>>> another
>>>>>>>> instance of the  entity and not the one that was populated by struts.
>>>>>>>>                 
>>>>>>> Lazy initialization (via null check or by setting an instance var), or
>>>>>>> config through Spring, or...
>>>>>>>               
>>>>>> If your getModel() puts the model entity on an instance variable, won't
>>>>>> that confuse the param interceptor?
>>>>>>             
>>>>> Depends on what instance variable you put it in, I suppose. One of your
>>>>> questions was how to access the model object w/o running through a
>>>>> getModel()
>>>>> method that would re-instantiate; lazily initializing an instance
>>>>> variable in
>>>>> getModel() then using that instance variable is one way of dealing
>>>>> with that.
>>>>>           
>>>> OK, that makes sense now, thanks. What I thought would be the more
>>>> obvious way of obtaining the model would be to fetch it from where
>>>> struts puts it when it calls getModel(), i.e. the value stack, however
>>>> I don't see any access methods for doing that, particulary on
>>>> ActionSupport.
>>>>         
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>     
>
>
>
>   


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


Re: preparable vs modelDriven

Posted by Musachy Barroso <mu...@gmail.com>.
Struts will by default populate parameters in your action, if you use
ModelDriven, then you can supply the object that will be populated
instead of the action. Implementing preparable will make struts call
prepare() before the action is executed, or prepareX() before X() is
executed. They are just sometimes used together to achieve certain
things, as explained on the other emails.

musachy

On Jan 31, 2008 5:03 PM, Adam Hardy <ah...@cyberspaceroad.com> wrote:
> I don't think you are strictly conveying the intended usage, when you say that
> the getModel() method will 'later' return the model. It depends how your
> interceptor stack is ordered. In the docs, it explicitly says the
> ModelDrivenInterceptor should come before ParametersInterceptor, as often the
> PrepareInterceptor does.
>
> Both ModelDriven- and PrepareInterceptor can retrieve the model and place it in
> instance variables on the action.
>
> http://struts.apache.org/2.0.11/docs/prepare-interceptor.html
>
> http://struts.apache.org/2.0.11/docs/model-driven-interceptor.html
>
> What I originally wanted to ask (whether I conveyed my question correctly is
> another matter) was: what's the difference in intention and implementation
> between these two?
>
> Thanks
> Adam
>
> Roberto Nunnari on 31/01/08 18:12, wrote:
> > The prepare() method task is to retrive the model
> > and store it as an instance variable.
> >
> > The getModel() method will later return the model
> > when asked by the framework that will put it on the
> > value stack.
> >
> > Please correct me if I'm wrong.
> >
>
> > Adam Hardy wrote:
> >> Dave Newton on 31/01/08 16:00, wrote:
> >>> Adam Hardy <ah...@cyberspaceroad.com> wrote:
> >>>> Dave Newton on 31/01/08 15:29, wrote:
> >>>>> Adam Hardy <ah...@cyberspaceroad.com> wrote:
> >>>>>> * ModelDriven: how do I get hold of my model during my action
> >>>>>> methods? I
> >>>>>> don't  want to get getModel() again, because that will retrieve
> >>>>>> another
> >>>>>> instance of the  entity and not the one that was populated by struts.
> >>>>> Lazy initialization (via null check or by setting an instance var), or
> >>>>> config through Spring, or...
> >>>> If your getModel() puts the model entity on an instance variable, won't
> >>>> that confuse the param interceptor?
> >>>
> >>> Depends on what instance variable you put it in, I suppose. One of your
> >>> questions was how to access the model object w/o running through a
> >>> getModel()
> >>> method that would re-instantiate; lazily initializing an instance
> >>> variable in
> >>> getModel() then using that instance variable is one way of dealing
> >>> with that.
> >>
> >> OK, that makes sense now, thanks. What I thought would be the more
> >> obvious way of obtaining the model would be to fetch it from where
> >> struts puts it when it calls getModel(), i.e. the value stack, however
> >> I don't see any access methods for doing that, particulary on
> >> ActionSupport.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

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


RE: preparable vs modelDriven

Posted by "Shannon, Andrew" <an...@pqa.com>.
I recently made use of model driven and preparable using some of the
advice provided in Roughley's book, and got a clear picture of how these
interceptors work from the forthcoming Manning book.  Our situation
required 2 different actions (one provides the form that posts to
another that does the save).  We're using annotated validation on our
model with custom validators.  This created the need for model driven in
order for the field names to sync up across actions and for the text
field tags to have the same field info in order to do the right
decoration on field error.  

The key to making it work was this interceptor stack:

<default-interceptor-ref name="paramsPrepareParamsStack"/> which I
didn't see anyone mention yet.

Understanding what to do with preparable and getModel was a little
tricky, and I think the important thing for me was to make sure my
action was doing one thing. Action 1 - Provide the model to a form.
Action 2 - Handle the form posted model.

Action 1 only had getModel and the property declaration for the model,
but no setter/getter.  Prepare took care of setting it, and action 1 was
nice and clean.

Action 2 on the other hand did require the setter/getter plus getModel
and a somewhat strange prepare() in order for info to be made available
from the value stack back to the INPUT result when field errors occur.
Here's the prepare() statement:

    public void prepare() throws Exception {
        if (site == null) {
            site = new Site();
        } else {
            site = getSite();
        }
    }

Since this action handels a form post it makes sense that site is null
and to create a new one that then gets populated with all the form data.
The } else { site = getSite() } part is a kludge and is there strictly
so I can run a test against this action.  I could not figure out a way
to get a mocked up site object into the action without doing this.

Has anyone unit tested model driven/preparable actions in this format?

Testing these with the BaseStrutsTestCase found at arsenalist.com was
illuminating to make sure these actions worked.  If you haven't used the
test case provided there you need to check it out and start using it
when writing these kinds of actions.

I hope some of this makes sense.

Thanks,
Andrew


-----Original Message-----
From: Adam Hardy [mailto:ahardy.struts@cyberspaceroad.com] 
Sent: Thursday, January 31, 2008 5:03 PM
To: Struts Users Mailing List
Subject: Re: preparable vs modelDriven

I don't think you are strictly conveying the intended usage, when you
say that the getModel() method will 'later' return the model. It depends
how your interceptor stack is ordered. In the docs, it explicitly says
the ModelDrivenInterceptor should come before ParametersInterceptor, as
often the PrepareInterceptor does.

Both ModelDriven- and PrepareInterceptor can retrieve the model and
place it in instance variables on the action.

http://struts.apache.org/2.0.11/docs/prepare-interceptor.html

http://struts.apache.org/2.0.11/docs/model-driven-interceptor.html

What I originally wanted to ask (whether I conveyed my question
correctly is another matter) was: what's the difference in intention and
implementation between these two?

Thanks
Adam

Roberto Nunnari on 31/01/08 18:12, wrote:
> The prepare() method task is to retrive the model and store it as an 
> instance variable.
> 
> The getModel() method will later return the model when asked by the 
> framework that will put it on the value stack.
> 
> Please correct me if I'm wrong.
> 
> Adam Hardy wrote:
>> Dave Newton on 31/01/08 16:00, wrote:
>>> Adam Hardy <ah...@cyberspaceroad.com> wrote:
>>>> Dave Newton on 31/01/08 15:29, wrote:
>>>>> Adam Hardy <ah...@cyberspaceroad.com> wrote:
>>>>>> * ModelDriven: how do I get hold of my model during my action 
>>>>>> methods? I don't  want to get getModel() again, because that will

>>>>>> retrieve another instance of the  entity and not the one that was

>>>>>> populated by struts.
>>>>> Lazy initialization (via null check or by setting an instance 
>>>>> var), or config through Spring, or...
>>>> If your getModel() puts the model entity on an instance variable, 
>>>> won't that confuse the param interceptor?
>>>
>>> Depends on what instance variable you put it in, I suppose. One of 
>>> your questions was how to access the model object w/o running 
>>> through a
>>> getModel()
>>> method that would re-instantiate; lazily initializing an instance 
>>> variable in
>>> getModel() then using that instance variable is one way of dealing 
>>> with that.
>>
>> OK, that makes sense now, thanks. What I thought would be the more 
>> obvious way of obtaining the model would be to fetch it from where 
>> struts puts it when it calls getModel(), i.e. the value stack, 
>> however I don't see any access methods for doing that, particulary on

>> ActionSupport.


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


Re: preparable vs modelDriven

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
I don't think you are strictly conveying the intended usage, when you say that 
the getModel() method will 'later' return the model. It depends how your 
interceptor stack is ordered. In the docs, it explicitly says the 
ModelDrivenInterceptor should come before ParametersInterceptor, as often the 
PrepareInterceptor does.

Both ModelDriven- and PrepareInterceptor can retrieve the model and place it in 
instance variables on the action.

http://struts.apache.org/2.0.11/docs/prepare-interceptor.html

http://struts.apache.org/2.0.11/docs/model-driven-interceptor.html

What I originally wanted to ask (whether I conveyed my question correctly is 
another matter) was: what's the difference in intention and implementation 
between these two?

Thanks
Adam

Roberto Nunnari on 31/01/08 18:12, wrote:
> The prepare() method task is to retrive the model
> and store it as an instance variable.
> 
> The getModel() method will later return the model
> when asked by the framework that will put it on the
> value stack.
> 
> Please correct me if I'm wrong.
> 
> Adam Hardy wrote:
>> Dave Newton on 31/01/08 16:00, wrote:
>>> Adam Hardy <ah...@cyberspaceroad.com> wrote:
>>>> Dave Newton on 31/01/08 15:29, wrote:
>>>>> Adam Hardy <ah...@cyberspaceroad.com> wrote:
>>>>>> * ModelDriven: how do I get hold of my model during my action 
>>>>>> methods? I
>>>>>> don't  want to get getModel() again, because that will retrieve 
>>>>>> another
>>>>>> instance of the  entity and not the one that was populated by struts.
>>>>> Lazy initialization (via null check or by setting an instance var), or
>>>>> config through Spring, or...
>>>> If your getModel() puts the model entity on an instance variable, won't
>>>> that confuse the param interceptor? 
>>>
>>> Depends on what instance variable you put it in, I suppose. One of your
>>> questions was how to access the model object w/o running through a 
>>> getModel()
>>> method that would re-instantiate; lazily initializing an instance 
>>> variable in
>>> getModel() then using that instance variable is one way of dealing 
>>> with that.
>>
>> OK, that makes sense now, thanks. What I thought would be the more 
>> obvious way of obtaining the model would be to fetch it from where 
>> struts puts it when it calls getModel(), i.e. the value stack, however 
>> I don't see any access methods for doing that, particulary on 
>> ActionSupport.


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


Re: preparable vs modelDriven

Posted by Roberto Nunnari <ro...@supsi.ch>.
Dave Newton wrote:
> --- Roberto Nunnari <ro...@supsi.ch> wrote:
>> The prepare() method task is to retrive the model
>> and store it as an instance variable.
>>
>> The getModel() method will later return the model
>> when asked by the framework that will put it on the
>> value stack.
>>
>> Please correct me if I'm wrong.
> 
> Some people use getModel() to do more work, that's all; the original question
> was how to avoid some of the issues caused by using that pattern.

I see. Sorry for the noise.

Robi.


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


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


Re: preparable vs modelDriven

Posted by Dave Newton <ne...@yahoo.com>.
--- Roberto Nunnari <ro...@supsi.ch> wrote:
> The prepare() method task is to retrive the model
> and store it as an instance variable.
> 
> The getModel() method will later return the model
> when asked by the framework that will put it on the
> value stack.
> 
> Please correct me if I'm wrong.

Some people use getModel() to do more work, that's all; the original question
was how to avoid some of the issues caused by using that pattern.

Dave


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


Re: preparable vs modelDriven

Posted by Roberto Nunnari <ro...@supsi.ch>.
The prepare() method task is to retrive the model
and store it as an instance variable.

The getModel() method will later return the model
when asked by the framework that will put it on the
value stack.

Please correct me if I'm wrong.

Best regards.

--
Robi



Adam Hardy wrote:
> Dave Newton on 31/01/08 16:00, wrote:
>> Adam Hardy <ah...@cyberspaceroad.com> wrote:
>>> Dave Newton on 31/01/08 15:29, wrote:
>>>> Adam Hardy <ah...@cyberspaceroad.com> wrote:
>>>>> * ModelDriven: how do I get hold of my model during my action 
>>>>> methods? I
>>>>> don't  want to get getModel() again, because that will retrieve 
>>>>> another
>>>>> instance of the  entity and not the one that was populated by struts.
>>>> Lazy initialization (via null check or by setting an instance var), or
>>>> config through Spring, or...
>>> If your getModel() puts the model entity on an instance variable, won't
>>> that confuse the param interceptor? 
>>
>> Depends on what instance variable you put it in, I suppose. One of your
>> questions was how to access the model object w/o running through a 
>> getModel()
>> method that would re-instantiate; lazily initializing an instance 
>> variable in
>> getModel() then using that instance variable is one way of dealing 
>> with that.
> 
> OK, that makes sense now, thanks. What I thought would be the more 
> obvious way of obtaining the model would be to fetch it from where 
> struts puts it when it calls getModel(), i.e. the value stack, however I 
> don't see any access methods for doing that, particulary on ActionSupport.
> 
> 
> Adam
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 


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


Re: preparable vs modelDriven

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
Dave Newton on 31/01/08 16:00, wrote:
> Adam Hardy <ah...@cyberspaceroad.com> wrote:
>> Dave Newton on 31/01/08 15:29, wrote:
>>> Adam Hardy <ah...@cyberspaceroad.com> wrote:
>>>> * ModelDriven: how do I get hold of my model during my action methods? I
>>>> don't  want to get getModel() again, because that will retrieve another
>>>> instance of the  entity and not the one that was populated by struts.
>>> Lazy initialization (via null check or by setting an instance var), or
>>> config through Spring, or...
>> If your getModel() puts the model entity on an instance variable, won't
>> that confuse the param interceptor? 
> 
> Depends on what instance variable you put it in, I suppose. One of your
> questions was how to access the model object w/o running through a getModel()
> method that would re-instantiate; lazily initializing an instance variable in
> getModel() then using that instance variable is one way of dealing with that.

OK, that makes sense now, thanks. What I thought would be the more obvious way 
of obtaining the model would be to fetch it from where struts puts it when it 
calls getModel(), i.e. the value stack, however I don't see any access methods 
for doing that, particulary on ActionSupport.


Adam

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


Re: preparable vs modelDriven

Posted by Dave Newton <ne...@yahoo.com>.
Adam Hardy <ah...@cyberspaceroad.com> wrote:
> Dave Newton on 31/01/08 15:29, wrote:
>> Adam Hardy <ah...@cyberspaceroad.com> wrote:
>>> * ModelDriven: how do I get hold of my model during my action methods? I
>>> don't  want to get getModel() again, because that will retrieve another
>>> instance of the  entity and not the one that was populated by struts.
>> 
>> Lazy initialization (via null check or by setting an instance var), or
>> config through Spring, or...
> 
> If your getModel() puts the model entity on an instance variable, won't
> that confuse the param interceptor? 

Depends on what instance variable you put it in, I suppose. One of your
questions was how to access the model object w/o running through a getModel()
method that would re-instantiate; lazily initializing an instance variable in
getModel() then using that instance variable is one way of dealing with that.

> Then it'll have the choice of populating the model it got from 
> getModel() and it'll see that there's a model entity on the action
> too.

Again, this is a different issue than I answered. But nobody says the
instance variable needs to be a publicly-accessible JavaBean property.

Dave


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


Re: preparable vs modelDriven

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
Dave Newton on 31/01/08 15:29, wrote:
> --- Adam Hardy <ah...@cyberspaceroad.com> wrote:
>> * ModelDriven: how do I get hold of my model during my action methods? I
>> don't  want to get getModel() again, because that will retrieve another
> instance
>> of the  entity and not the one that was populated by struts.
> 
> Lazy initialization (via null check or by setting an instance var), or config
> through Spring, or...

If your getModel() puts the model entity on an instance variable, won't that 
confuse the param interceptor? Then it'll have the choice of populating the 
model it got from getModel() and it'll see that there's a model entity on the 
action too.


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


Re: preparable vs modelDriven

Posted by Dave Newton <ne...@yahoo.com>.
--- Adam Hardy <ah...@cyberspaceroad.com> wrote:
> Is my understanding correct that Preparable and ModelDriven are 2 different
> ways of doing the same thing, or are they complementary in any way?

They *could* be used to do the same thing, but IMO Preparable is more
general-purpose than ModelDriven, and that's only if you're doing your model
retrieval work in the actual model getter (which I guess a lot of people do?)

> * ModelDriven: how do I get hold of my model during my action methods? I
> don't  want to get getModel() again, because that will retrieve another
instance
> of the  entity and not the one that was populated by struts.

Lazy initialization (via null check or by setting an instance var), or config
through Spring, or...

> * why do param-prepare-param instead of just prepare-param with
> ServletActionContext.getRequest().getParameter("id") in prepare,
> which would save a whole cycle through the param interceptor?

Most likely to remove that step from the mainline code. It probably depends
on how much logic is dependent on how many parameters.

Personally I don't use Preparable very much, but that's just me and isn't a
general commentary on its usefulness. I just find doing it "manually" is a
bit more clear, particularly when I'm not the only person working on the
code, even more so when the others aren't as used to the S2 request cycle.

I'd definitely be interested in hearing other people's take on this issue,
though, as I try to decide what long-term habits to use for S2 development.

Dave



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