You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Scott Koenig <sc...@gmail.com> on 2012/03/26 17:03:26 UTC

setter overriding?

I have a model-driven Web action:

    public class ModelDrivenAction<T extends Object> implements
ModelDriven<T>, Preparable {

      protected Long id;
      protected T model;

      @Override
      public void prepare() {}

      public void setId(Long id) { this.id = id; }

      @Override
      public T getModel() { return model; }

      public void setModel(T model) { this.model = model; }
    }

I have another action which is not currently model-driven:

    public class OtherAction implements Preparable {

      private ModelObj modelObj;
      private Long modelId;

      @Override
      public void prepare() { modelObj =
repoService.retrieveModelById(modelId); }

      public void setModelId(Long modelId) { this.modelId = modelId; }
    }

I wish to use the model-driven action to extend the other action, and would
like to avoid having to track down all the instances in JavaScript where
the action is passed a "modelId" parameter instead of "id" if at all
possible. I thought this might work, so either modelId or id could be
passed in:

    public class OtherAction extends ModelDrivenAction<ModelObj> {

      @Override
      public void prepare() { model = repoService.retrieveModelById(id); }

      public void setModelId(Long modelId) { this.id = modelId; }
    }

However, server/path/to/other!method?modelId=123 is failing to set id. I
thought so long as a setter matched a parameter name the Struts interceptor
would call it on action invocation. Am I missing something here? I'm using
Java 6, Struts 2.1.8.1 and Spring 3.

Re: setter overriding?

Posted by Dave Newton <da...@gmail.com>.
http://struts.apache.org/mail.html

On Monday, March 26, 2012, Yadav Khanal <ya...@yahoo.com> wrote:
> I wanna get rid of the mass mail; How may I unsubscribe?
>
>
> ________________________________
>  From: Dave Newton <da...@gmail.com>
> To: Struts Users Mailing List <us...@struts.apache.org>
> Sent: Monday, March 26, 2012 11:07:04 AM
> Subject: Re: setter overriding?
>
> I *think* it'd try to set `modelId` on the model, not on the action--I'd
> have to check the source.
>
> d.
>
> On Mon, Mar 26, 2012 at 11:03 AM, Scott Koenig <scott.l.koenig@gmail.com
>wrote:
>
>> I have a model-driven Web action:
>>
>>    public class ModelDrivenAction<T extends Object> implements
>> ModelDriven<T>, Preparable {
>>
>>      protected Long id;
>>      protected T model;
>>
>>      @Override
>>      public void prepare() {}
>>
>>      public void setId(Long id) { this.id = id; }
>>
>>      @Override
>>      public T getModel() { return model; }
>>
>>      public void setModel(T model) { this.model = model; }
>>    }
>>
>> I have another action which is not currently model-driven:
>>
>>    public class OtherAction implements Preparable {
>>
>>      private ModelObj modelObj;
>>      private Long modelId;
>>
>>      @Override
>>      public void prepare() { modelObj =
>> repoService.retrieveModelById(modelId); }
>>
>>      public void setModelId(Long modelId) { this.modelId = modelId; }
>>    }
>>
>> I wish to use the model-driven action to extend the other action, and
would
>> like to avoid having to track down all the instances in JavaScript where
>> the action is passed a "modelId" parameter instead of "id" if at all
>> possible. I thought this might work, so either modelId or id could be
>> passed in:
>>
>>    public class OtherAction extends ModelDrivenAction<ModelObj> {
>>
>>      @Override
>>      public void prepare() { model = repoService.retrieveModelById(id); }
>>
>>      public void setModelId(Long modelId) { this.id = modelId; }
>>    }
>>
>> However, server/path/to/other!method?modelId=123 is failing to set id. I
>> thought so long as a setter matched a parameter name the Struts
interceptor
>> would call it on action invocation. Am I missing something here? I'm
using
>> Java 6, Struts 2.1.8.1 and Spring 3.
>>

Re: setter overriding?

Posted by Yadav Khanal <ya...@yahoo.com>.
I wanna get rid of the mass mail; How may I unsubscribe?


________________________________
 From: Dave Newton <da...@gmail.com>
To: Struts Users Mailing List <us...@struts.apache.org> 
Sent: Monday, March 26, 2012 11:07:04 AM
Subject: Re: setter overriding?
 
I *think* it'd try to set `modelId` on the model, not on the action--I'd
have to check the source.

d.

On Mon, Mar 26, 2012 at 11:03 AM, Scott Koenig <sc...@gmail.com>wrote:

> I have a model-driven Web action:
>
>    public class ModelDrivenAction<T extends Object> implements
> ModelDriven<T>, Preparable {
>
>      protected Long id;
>      protected T model;
>
>      @Override
>      public void prepare() {}
>
>      public void setId(Long id) { this.id = id; }
>
>      @Override
>      public T getModel() { return model; }
>
>      public void setModel(T model) { this.model = model; }
>    }
>
> I have another action which is not currently model-driven:
>
>    public class OtherAction implements Preparable {
>
>      private ModelObj modelObj;
>      private Long modelId;
>
>      @Override
>      public void prepare() { modelObj =
> repoService.retrieveModelById(modelId); }
>
>      public void setModelId(Long modelId) { this.modelId = modelId; }
>    }
>
> I wish to use the model-driven action to extend the other action, and would
> like to avoid having to track down all the instances in JavaScript where
> the action is passed a "modelId" parameter instead of "id" if at all
> possible. I thought this might work, so either modelId or id could be
> passed in:
>
>    public class OtherAction extends ModelDrivenAction<ModelObj> {
>
>      @Override
>      public void prepare() { model = repoService.retrieveModelById(id); }
>
>      public void setModelId(Long modelId) { this.id = modelId; }
>    }
>
> However, server/path/to/other!method?modelId=123 is failing to set id. I
> thought so long as a setter matched a parameter name the Struts interceptor
> would call it on action invocation. Am I missing something here? I'm using
> Java 6, Struts 2.1.8.1 and Spring 3.
>

Re: setter overriding?

Posted by Scott Koenig <sc...@gmail.com>.
Just to follow up: turns out the issue was due to a misconfiguration in
Eclipse; the code actually does work as I'd expected.

On Mon, Mar 26, 2012 at 11:48 AM, Dave Newton <da...@gmail.com> wrote:

> The model driven and params interceptors, I think--it should be pretty
> quick to track.
>
> d.
>
> On Mon, Mar 26, 2012 at 11:42 AM, Scott Koenig <scott.l.koenig@gmail.com
> >wrote:
>
> > Thanks, Dave... I'll probably end up just tracking down all the places in
> > the js, but I'd like to investigate this just to satisfy my curiosity...
> do
> > you have any suggestions on which file(s) to examine in the source?
> >
> > On Mon, Mar 26, 2012 at 11:07 AM, Dave Newton <da...@gmail.com>
> > wrote:
> >
> > > I *think* it'd try to set `modelId` on the model, not on the
> action--I'd
> > > have to check the source.
> > >
> > > d.
> > >
> > > On Mon, Mar 26, 2012 at 11:03 AM, Scott Koenig <
> scott.l.koenig@gmail.com
> > > >wrote:
> > >
> > > > I have a model-driven Web action:
> > > >
> > > >    public class ModelDrivenAction<T extends Object> implements
> > > > ModelDriven<T>, Preparable {
> > > >
> > > >      protected Long id;
> > > >      protected T model;
> > > >
> > > >      @Override
> > > >      public void prepare() {}
> > > >
> > > >      public void setId(Long id) { this.id = id; }
> > > >
> > > >      @Override
> > > >      public T getModel() { return model; }
> > > >
> > > >      public void setModel(T model) { this.model = model; }
> > > >    }
> > > >
> > > > I have another action which is not currently model-driven:
> > > >
> > > >    public class OtherAction implements Preparable {
> > > >
> > > >      private ModelObj modelObj;
> > > >      private Long modelId;
> > > >
> > > >      @Override
> > > >      public void prepare() { modelObj =
> > > > repoService.retrieveModelById(modelId); }
> > > >
> > > >      public void setModelId(Long modelId) { this.modelId = modelId; }
> > > >    }
> > > >
> > > > I wish to use the model-driven action to extend the other action, and
> > > would
> > > > like to avoid having to track down all the instances in JavaScript
> > where
> > > > the action is passed a "modelId" parameter instead of "id" if at all
> > > > possible. I thought this might work, so either modelId or id could be
> > > > passed in:
> > > >
> > > >    public class OtherAction extends ModelDrivenAction<ModelObj> {
> > > >
> > > >      @Override
> > > >      public void prepare() { model =
> > repoService.retrieveModelById(id); }
> > > >
> > > >      public void setModelId(Long modelId) { this.id = modelId; }
> > > >    }
> > > >
> > > > However, server/path/to/other!method?modelId=123 is failing to set
> id.
> > I
> > > > thought so long as a setter matched a parameter name the Struts
> > > interceptor
> > > > would call it on action invocation. Am I missing something here? I'm
> > > using
> > > > Java 6, Struts 2.1.8.1 and Spring 3.
> > > >
> > >
> >
>

Re: setter overriding?

Posted by Dave Newton <da...@gmail.com>.
The model driven and params interceptors, I think--it should be pretty
quick to track.

d.

On Mon, Mar 26, 2012 at 11:42 AM, Scott Koenig <sc...@gmail.com>wrote:

> Thanks, Dave... I'll probably end up just tracking down all the places in
> the js, but I'd like to investigate this just to satisfy my curiosity... do
> you have any suggestions on which file(s) to examine in the source?
>
> On Mon, Mar 26, 2012 at 11:07 AM, Dave Newton <da...@gmail.com>
> wrote:
>
> > I *think* it'd try to set `modelId` on the model, not on the action--I'd
> > have to check the source.
> >
> > d.
> >
> > On Mon, Mar 26, 2012 at 11:03 AM, Scott Koenig <scott.l.koenig@gmail.com
> > >wrote:
> >
> > > I have a model-driven Web action:
> > >
> > >    public class ModelDrivenAction<T extends Object> implements
> > > ModelDriven<T>, Preparable {
> > >
> > >      protected Long id;
> > >      protected T model;
> > >
> > >      @Override
> > >      public void prepare() {}
> > >
> > >      public void setId(Long id) { this.id = id; }
> > >
> > >      @Override
> > >      public T getModel() { return model; }
> > >
> > >      public void setModel(T model) { this.model = model; }
> > >    }
> > >
> > > I have another action which is not currently model-driven:
> > >
> > >    public class OtherAction implements Preparable {
> > >
> > >      private ModelObj modelObj;
> > >      private Long modelId;
> > >
> > >      @Override
> > >      public void prepare() { modelObj =
> > > repoService.retrieveModelById(modelId); }
> > >
> > >      public void setModelId(Long modelId) { this.modelId = modelId; }
> > >    }
> > >
> > > I wish to use the model-driven action to extend the other action, and
> > would
> > > like to avoid having to track down all the instances in JavaScript
> where
> > > the action is passed a "modelId" parameter instead of "id" if at all
> > > possible. I thought this might work, so either modelId or id could be
> > > passed in:
> > >
> > >    public class OtherAction extends ModelDrivenAction<ModelObj> {
> > >
> > >      @Override
> > >      public void prepare() { model =
> repoService.retrieveModelById(id); }
> > >
> > >      public void setModelId(Long modelId) { this.id = modelId; }
> > >    }
> > >
> > > However, server/path/to/other!method?modelId=123 is failing to set id.
> I
> > > thought so long as a setter matched a parameter name the Struts
> > interceptor
> > > would call it on action invocation. Am I missing something here? I'm
> > using
> > > Java 6, Struts 2.1.8.1 and Spring 3.
> > >
> >
>

Re: setter overriding?

Posted by Scott Koenig <sc...@gmail.com>.
Thanks, Dave... I'll probably end up just tracking down all the places in
the js, but I'd like to investigate this just to satisfy my curiosity... do
you have any suggestions on which file(s) to examine in the source?

On Mon, Mar 26, 2012 at 11:07 AM, Dave Newton <da...@gmail.com> wrote:

> I *think* it'd try to set `modelId` on the model, not on the action--I'd
> have to check the source.
>
> d.
>
> On Mon, Mar 26, 2012 at 11:03 AM, Scott Koenig <scott.l.koenig@gmail.com
> >wrote:
>
> > I have a model-driven Web action:
> >
> >    public class ModelDrivenAction<T extends Object> implements
> > ModelDriven<T>, Preparable {
> >
> >      protected Long id;
> >      protected T model;
> >
> >      @Override
> >      public void prepare() {}
> >
> >      public void setId(Long id) { this.id = id; }
> >
> >      @Override
> >      public T getModel() { return model; }
> >
> >      public void setModel(T model) { this.model = model; }
> >    }
> >
> > I have another action which is not currently model-driven:
> >
> >    public class OtherAction implements Preparable {
> >
> >      private ModelObj modelObj;
> >      private Long modelId;
> >
> >      @Override
> >      public void prepare() { modelObj =
> > repoService.retrieveModelById(modelId); }
> >
> >      public void setModelId(Long modelId) { this.modelId = modelId; }
> >    }
> >
> > I wish to use the model-driven action to extend the other action, and
> would
> > like to avoid having to track down all the instances in JavaScript where
> > the action is passed a "modelId" parameter instead of "id" if at all
> > possible. I thought this might work, so either modelId or id could be
> > passed in:
> >
> >    public class OtherAction extends ModelDrivenAction<ModelObj> {
> >
> >      @Override
> >      public void prepare() { model = repoService.retrieveModelById(id); }
> >
> >      public void setModelId(Long modelId) { this.id = modelId; }
> >    }
> >
> > However, server/path/to/other!method?modelId=123 is failing to set id. I
> > thought so long as a setter matched a parameter name the Struts
> interceptor
> > would call it on action invocation. Am I missing something here? I'm
> using
> > Java 6, Struts 2.1.8.1 and Spring 3.
> >
>

Re: setter overriding?

Posted by Dave Newton <da...@gmail.com>.
I *think* it'd try to set `modelId` on the model, not on the action--I'd
have to check the source.

d.

On Mon, Mar 26, 2012 at 11:03 AM, Scott Koenig <sc...@gmail.com>wrote:

> I have a model-driven Web action:
>
>    public class ModelDrivenAction<T extends Object> implements
> ModelDriven<T>, Preparable {
>
>      protected Long id;
>      protected T model;
>
>      @Override
>      public void prepare() {}
>
>      public void setId(Long id) { this.id = id; }
>
>      @Override
>      public T getModel() { return model; }
>
>      public void setModel(T model) { this.model = model; }
>    }
>
> I have another action which is not currently model-driven:
>
>    public class OtherAction implements Preparable {
>
>      private ModelObj modelObj;
>      private Long modelId;
>
>      @Override
>      public void prepare() { modelObj =
> repoService.retrieveModelById(modelId); }
>
>      public void setModelId(Long modelId) { this.modelId = modelId; }
>    }
>
> I wish to use the model-driven action to extend the other action, and would
> like to avoid having to track down all the instances in JavaScript where
> the action is passed a "modelId" parameter instead of "id" if at all
> possible. I thought this might work, so either modelId or id could be
> passed in:
>
>    public class OtherAction extends ModelDrivenAction<ModelObj> {
>
>      @Override
>      public void prepare() { model = repoService.retrieveModelById(id); }
>
>      public void setModelId(Long modelId) { this.id = modelId; }
>    }
>
> However, server/path/to/other!method?modelId=123 is failing to set id. I
> thought so long as a setter matched a parameter name the Struts interceptor
> would call it on action invocation. Am I missing something here? I'm using
> Java 6, Struts 2.1.8.1 and Spring 3.
>