You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Taylor Cowan <tc...@silverstream.com> on 2001/11/10 16:23:23 UTC

Suggest ActionMapping assigned at action instantiation

The ActionMapping has a 1 to 1 relationship with an instance of Action,
therefore, it could be assigned to the action when it is instantiated.
Instead of passing it to each perform() the client code could access it with
a method:

this.getActionMapping();

REASON:
There are times when you want to do one-time-only processing based on
something defined in the map ( which applies to all sessions of course).
The constructor could be overriden to handle that:

	public Action( ActionMapping map ) {
		super(map);
		// my startup processing

	}

For reference, I'd compare this to Servlets and ServletConfig.

Taylor



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Suggest ActionMapping assigned at action instantiation

Posted by Ted Husted <hu...@apache.org>.
Each ActionMapping can specify a single Action, but an Action can be
specified by any number of ActionMappings. So, an Action may needs to
know which ActionMapping was used to invoke it.

Since there is only one Action instance per application, I suppose you
could handle the "one time processing" by setting a property on the
Action. Once it was set, other Actions would not perform the processing.
Though, you would need to synchronize the setting along with the
processing, to avoid threading issues.

-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel +1 716 737-3463
-- http://www.husted.com/struts/


Taylor Cowan wrote:
> 
> The ActionMapping has a 1 to 1 relationship with an instance of Action,
> therefore, it could be assigned to the action when it is instantiated.
> Instead of passing it to each perform() the client code could access it with
> a method:
> 
> this.getActionMapping();
> 
> REASON:
> There are times when you want to do one-time-only processing based on
> something defined in the map ( which applies to all sessions of course).
> The constructor could be overriden to handle that:
> 
>         public Action( ActionMapping map ) {
>                 super(map);
>                 // my startup processing
> 
>         }
> 
> For reference, I'd compare this to Servlets and ServletConfig.
> 
> Taylor
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Suggest ActionMapping assigned at action instantiation

Posted by Ted Husted <hu...@apache.org>.
Though, the original ActionConfig idea is pretty cool, and it would be
interesting if this were something that could be read from the Struts
configuration. On initialization, the ActionServlet could check for a
node, and then call some init's on the Action class (with the
understanding that all the mappings would use these). 

<action-configs>

<action-config 
 type="com.whatever.MyAction">
    <init-param> 
      <param-name>myProperty</param-name> 
      <param-value>some value</param-value> 
    </init-param> 
</action-config>

 </action-configs>

As the community grows, more "utility" Actions may become available, and
this would give people a simple way to set defaults for an Action
without recompiling.

Taylor might want to submit this as an enhancement request to bugzilla,
or even think about patching together an implementation ;-)

-Ted.


"Craig R. McClanahan" wrote:
> 
> OOPS ... mea culpa ...
> 
> Ted pointed out (in private mail) that I had mis-remembered how action
> instances are mapped.  I assumed they were per-mapping, they are actually
> per-class-name.  So, there is only one instance of an Action for each
> fully qualified class name, which is why the mapping argument *must* be
> passed to the perform() method.
> 
> For one-time initialization that is specific to the mapping being used, I
> would keep a HashMap or something inside the action class that was keyed
> by the mapping path in use, and use that as a flag for whether per-mapping
> initialization is needed.
> 
> Craig
> 
> On Sat, 10 Nov 2001, Craig R. McClanahan wrote:
> 
> > Date: Sat, 10 Nov 2001 10:46:45 -0800 (PST)
> > From: Craig R. McClanahan <cr...@apache.org>
> > Reply-To: Struts Developers List <st...@jakarta.apache.org>
> > To: Struts Developers List <st...@jakarta.apache.org>
> > Subject: Re: Suggest ActionMapping assigned at action instantiation
> >
> >
> >
> > On Sat, 10 Nov 2001, Taylor Cowan wrote:
> >
> > > Date: Sat, 10 Nov 2001 10:23:23 -0500
> > > From: Taylor Cowan <tc...@silverstream.com>
> > > Reply-To: Struts Developers List <st...@jakarta.apache.org>
> > > To: struts-dev@jakarta.apache.org
> > > Subject: Suggest ActionMapping assigned at action instantiation
> > >
> > > The ActionMapping has a 1 to 1 relationship with an instance of Action,
> > > therefore, it could be assigned to the action when it is instantiated.
> > > Instead of passing it to each perform() the client code could access it with
> > > a method:
> > >
> > > this.getActionMapping();
> > >
> > > REASON:
> > > There are times when you want to do one-time-only processing based on
> > > something defined in the map ( which applies to all sessions of course).
> > > The constructor could be overriden to handle that:
> > >
> > >     public Action( ActionMapping map ) {
> > >             super(map);
> > >             // my startup processing
> > >
> > >     }
> > >
> > > For reference, I'd compare this to Servlets and ServletConfig.
> > >
> >
> > While the idea makes sense, I assume you would also advocate for removing
> > the "mapping" parameter from the perform() call, right?  Doing this would
> > break backwards compatibility with all existing Actions, which would be a
> > bad thing.  This is the kind of thing that should have been done
> > originally if it was going to be done.
> >
> > The current strategy also lets a subclassed controller servlet decide to
> > share the same Action instance for different mappings if it wanted to, and
> > the called Action instance would still be able to disambiguate them.
> >
> > (By the way, you can use a call to setServlet() with a non-null argument
> > as a convenient place to do per-Action-instance initialization.  Just as a
> > historical note, at the time this API was designed, the Servlet 2.3 expert
> > group was looking at a design for Filters that had something very similar.
> > The Filter API was changed in the manner that Taylor suggests, but
> > *before* release rather than after ;-).
> >
> >
> > > Taylor
> > >
> >
> > Craig
> >
> >
> > --
> > To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> > For additional commands, e-mail: <ma...@jakarta.apache.org>
> >
> >
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel +1 716 737-3463
-- http://www.husted.com/struts/

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Suggest ActionMapping assigned at action instantiation

Posted by "Craig R. McClanahan" <cr...@apache.org>.
OOPS ... mea culpa ...

Ted pointed out (in private mail) that I had mis-remembered how action
instances are mapped.  I assumed they were per-mapping, they are actually
per-class-name.  So, there is only one instance of an Action for each
fully qualified class name, which is why the mapping argument *must* be
passed to the perform() method.

For one-time initialization that is specific to the mapping being used, I
would keep a HashMap or something inside the action class that was keyed
by the mapping path in use, and use that as a flag for whether per-mapping
initialization is needed.

Craig


On Sat, 10 Nov 2001, Craig R. McClanahan wrote:

> Date: Sat, 10 Nov 2001 10:46:45 -0800 (PST)
> From: Craig R. McClanahan <cr...@apache.org>
> Reply-To: Struts Developers List <st...@jakarta.apache.org>
> To: Struts Developers List <st...@jakarta.apache.org>
> Subject: Re: Suggest ActionMapping assigned at action instantiation
>
>
>
> On Sat, 10 Nov 2001, Taylor Cowan wrote:
>
> > Date: Sat, 10 Nov 2001 10:23:23 -0500
> > From: Taylor Cowan <tc...@silverstream.com>
> > Reply-To: Struts Developers List <st...@jakarta.apache.org>
> > To: struts-dev@jakarta.apache.org
> > Subject: Suggest ActionMapping assigned at action instantiation
> >
> > The ActionMapping has a 1 to 1 relationship with an instance of Action,
> > therefore, it could be assigned to the action when it is instantiated.
> > Instead of passing it to each perform() the client code could access it with
> > a method:
> >
> > this.getActionMapping();
> >
> > REASON:
> > There are times when you want to do one-time-only processing based on
> > something defined in the map ( which applies to all sessions of course).
> > The constructor could be overriden to handle that:
> >
> > 	public Action( ActionMapping map ) {
> > 		super(map);
> > 		// my startup processing
> >
> > 	}
> >
> > For reference, I'd compare this to Servlets and ServletConfig.
> >
>
> While the idea makes sense, I assume you would also advocate for removing
> the "mapping" parameter from the perform() call, right?  Doing this would
> break backwards compatibility with all existing Actions, which would be a
> bad thing.  This is the kind of thing that should have been done
> originally if it was going to be done.
>
> The current strategy also lets a subclassed controller servlet decide to
> share the same Action instance for different mappings if it wanted to, and
> the called Action instance would still be able to disambiguate them.
>
> (By the way, you can use a call to setServlet() with a non-null argument
> as a convenient place to do per-Action-instance initialization.  Just as a
> historical note, at the time this API was designed, the Servlet 2.3 expert
> group was looking at a design for Filters that had something very similar.
> The Filter API was changed in the manner that Taylor suggests, but
> *before* release rather than after ;-).
>
>
> > Taylor
> >
>
> Craig
>
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Suggest ActionMapping assigned at action instantiation

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Sat, 10 Nov 2001, Taylor Cowan wrote:

> Date: Sat, 10 Nov 2001 10:23:23 -0500
> From: Taylor Cowan <tc...@silverstream.com>
> Reply-To: Struts Developers List <st...@jakarta.apache.org>
> To: struts-dev@jakarta.apache.org
> Subject: Suggest ActionMapping assigned at action instantiation
>
> The ActionMapping has a 1 to 1 relationship with an instance of Action,
> therefore, it could be assigned to the action when it is instantiated.
> Instead of passing it to each perform() the client code could access it with
> a method:
>
> this.getActionMapping();
>
> REASON:
> There are times when you want to do one-time-only processing based on
> something defined in the map ( which applies to all sessions of course).
> The constructor could be overriden to handle that:
>
> 	public Action( ActionMapping map ) {
> 		super(map);
> 		// my startup processing
>
> 	}
>
> For reference, I'd compare this to Servlets and ServletConfig.
>

While the idea makes sense, I assume you would also advocate for removing
the "mapping" parameter from the perform() call, right?  Doing this would
break backwards compatibility with all existing Actions, which would be a
bad thing.  This is the kind of thing that should have been done
originally if it was going to be done.

The current strategy also lets a subclassed controller servlet decide to
share the same Action instance for different mappings if it wanted to, and
the called Action instance would still be able to disambiguate them.

(By the way, you can use a call to setServlet() with a non-null argument
as a convenient place to do per-Action-instance initialization.  Just as a
historical note, at the time this API was designed, the Servlet 2.3 expert
group was looking at a design for Filters that had something very similar.
The Filter API was changed in the manner that Taylor suggests, but
*before* release rather than after ;-).


> Taylor
>

Craig


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>