You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Hicks, James" <Ja...@LMBerry.com> on 2001/08/18 00:18:19 UTC
Suggestion For Action Class
I would like to suggest adding a method called prePerform to match each
perform method in the org.apache.struts.action.Action class and have the
ActionServlet call it just before it calls perform. These prePerform method
would also return an ActionForward instance. If the ActionServlet received
an ActionForward from the prePerform, it would use it to forward the request
instead of calling the perform method.
This would ease development in a lot of projects.
For example, say I want to validate my visitor on each request. If I had a
prePerform method I could write a subclass of Action for my project called
MyProjectBaseAction and include the prePerform method. Inside of
prePerform, I could do the validation. This would allow me to take the
validation code out of each one of my specific action classes and never have
to worry about the validation logic changing. If it did change, I have one
place to change it instead of 50 or 100.
James Hicks
Re: Suggestion For Action Class
Posted by ma...@tumbleweed.com.
Filters are cool, but to use them, you need a container which supports
Servlets 2.3 (e.g. Tomcat 4 or Resin 2). Also, the spec isn't final yet, so
although I wouldn't expect much change between Proposed Final Draft 2 and
Final, it's still possible.
--
Martin Cooper
----- Original Message -----
From: "Dave Van Even" <da...@pandora.be>
To: <st...@jakarta.apache.org>
Sent: Sunday, August 19, 2001 1:16 PM
Subject: Re: Suggestion For Action Class
> hi,
>
> If you perform some kind of validation of your clients, I think it's best
to
> use
> filters. I don't know much about filters (yet), but take a look!! It looks
> geat..
>
> http://www.javaworld.com/javaworld/jw-01-2001/jw-0126-servletapi.html
> http://www.javaworld.com/javaworld/jw-06-2001/jw-0622-filters.html
>
> Dave Van Even
>
> ----- Original Message -----
> From: "Ted Husted" <hu...@apache.org>
> To: <st...@jakarta.apache.org>
> Sent: Sunday, August 19, 2001 4:11 PM
> Subject: Re: Suggestion For Action Class
>
>
> > Another approach, similar to the others suggested, is to define the
> > eqivalent of a postProcess() action. The base Action class does its
> > perform business, and if all is well, then returns the result of the new
> > method. This also allows you to change the signature of your new method,
> > if there is ever any reason for that. One example would be to pass a
> > login object from the session if that was used in all or most of the
> > Actions.
> >
> > public ActionForward perform(ActionMapping mapping,
> > ActionForm form,
> > HttpServletRequest request,
> > HttpServletResponse response)
> > throws IOException, ServletException {
> >
> > // Application specific behaviour
> > // if everything is kosher call subclass
> >
> > return ( performAction(mapping,form,request,response, myParameter ) )
> > }
> >
> > where performAction is an abstract method of the base class.
> >
> > -- Ted Husted, Husted dot Com, Fairport NY USA.
> > -- Custom Software ~ Technical Services.
> > -- Tel +1 716 737-3463
> > -- http://www.husted.com/about/struts/
> >
> >
> >
> > "Hicks, James" wrote:
> > >
> > > I would like to suggest adding a method called prePerform to match
each
> > > perform method in the org.apache.struts.action.Action class and have
the
> > > ActionServlet call it just before it calls perform. These prePerform
> method
> > > would also return an ActionForward instance. If the ActionServlet
> received
> > > an ActionForward from the prePerform, it would use it to forward the
> request
> > > instead of calling the perform method.
> > >
> > > This would ease development in a lot of projects.
> > >
> > > For example, say I want to validate my visitor on each request. If I
> had a
> > > prePerform method I could write a subclass of Action for my project
> called
> > > MyProjectBaseAction and include the prePerform method. Inside of
> > > prePerform, I could do the validation. This would allow me to take
the
> > > validation code out of each one of my specific action classes and
never
> have
> > > to worry about the validation logic changing. If it did change, I
have
> one
> > > place to change it instead of 50 or 100.
> > >
> > > James Hicks
> >
>
>
Re: Suggestion For Action Class
Posted by Dave Van Even <da...@pandora.be>.
hi,
If you perform some kind of validation of your clients, I think it's best to
use
filters. I don't know much about filters (yet), but take a look!! It looks
geat..
http://www.javaworld.com/javaworld/jw-01-2001/jw-0126-servletapi.html
http://www.javaworld.com/javaworld/jw-06-2001/jw-0622-filters.html
Dave Van Even
----- Original Message -----
From: "Ted Husted" <hu...@apache.org>
To: <st...@jakarta.apache.org>
Sent: Sunday, August 19, 2001 4:11 PM
Subject: Re: Suggestion For Action Class
> Another approach, similar to the others suggested, is to define the
> eqivalent of a postProcess() action. The base Action class does its
> perform business, and if all is well, then returns the result of the new
> method. This also allows you to change the signature of your new method,
> if there is ever any reason for that. One example would be to pass a
> login object from the session if that was used in all or most of the
> Actions.
>
> public ActionForward perform(ActionMapping mapping,
> ActionForm form,
> HttpServletRequest request,
> HttpServletResponse response)
> throws IOException, ServletException {
>
> // Application specific behaviour
> // if everything is kosher call subclass
>
> return ( performAction(mapping,form,request,response, myParameter ) )
> }
>
> where performAction is an abstract method of the base class.
>
> -- Ted Husted, Husted dot Com, Fairport NY USA.
> -- Custom Software ~ Technical Services.
> -- Tel +1 716 737-3463
> -- http://www.husted.com/about/struts/
>
>
>
> "Hicks, James" wrote:
> >
> > I would like to suggest adding a method called prePerform to match each
> > perform method in the org.apache.struts.action.Action class and have the
> > ActionServlet call it just before it calls perform. These prePerform
method
> > would also return an ActionForward instance. If the ActionServlet
received
> > an ActionForward from the prePerform, it would use it to forward the
request
> > instead of calling the perform method.
> >
> > This would ease development in a lot of projects.
> >
> > For example, say I want to validate my visitor on each request. If I
had a
> > prePerform method I could write a subclass of Action for my project
called
> > MyProjectBaseAction and include the prePerform method. Inside of
> > prePerform, I could do the validation. This would allow me to take the
> > validation code out of each one of my specific action classes and never
have
> > to worry about the validation logic changing. If it did change, I have
one
> > place to change it instead of 50 or 100.
> >
> > James Hicks
>
Re: Suggestion For Action Class
Posted by Ted Husted <hu...@apache.org>.
Another approach, similar to the others suggested, is to define the
eqivalent of a postProcess() action. The base Action class does its
perform business, and if all is well, then returns the result of the new
method. This also allows you to change the signature of your new method,
if there is ever any reason for that. One example would be to pass a
login object from the session if that was used in all or most of the
Actions.
public ActionForward perform(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
// Application specific behaviour
// if everything is kosher call subclass
return ( performAction(mapping,form,request,response, myParameter ) )
}
where performAction is an abstract method of the base class.
-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel +1 716 737-3463
-- http://www.husted.com/about/struts/
"Hicks, James" wrote:
>
> I would like to suggest adding a method called prePerform to match each
> perform method in the org.apache.struts.action.Action class and have the
> ActionServlet call it just before it calls perform. These prePerform method
> would also return an ActionForward instance. If the ActionServlet received
> an ActionForward from the prePerform, it would use it to forward the request
> instead of calling the perform method.
>
> This would ease development in a lot of projects.
>
> For example, say I want to validate my visitor on each request. If I had a
> prePerform method I could write a subclass of Action for my project called
> MyProjectBaseAction and include the prePerform method. Inside of
> prePerform, I could do the validation. This would allow me to take the
> validation code out of each one of my specific action classes and never have
> to worry about the validation logic changing. If it did change, I have one
> place to change it instead of 50 or 100.
>
> James Hicks
Re: Suggestion For Action Class
Posted by Anthony Xin Chen <xi...@tbcommerce.com>.
Hello James,
Your requirement could be solved by using "Template method pattern" in
your base Action.
The sketch of idea is as following:
1. In base action class
perform( ) {
prePerform();
myPerform();
}
2. In base action class, provides prePerform() method with validation
routine and a empty myPerform() method.
3. In derived action class, overides prePerform() and myPerform() as
necessary.
Hope it helps.
Friday, August 17, 2001, 3:18:19 PM, you wrote:
HJ> I would like to suggest adding a method called prePerform to match each
HJ> perform method in the org.apache.struts.action.Action class and have the
HJ> ActionServlet call it just before it calls perform. These prePerform method
HJ> would also return an ActionForward instance. If the ActionServlet received
HJ> an ActionForward from the prePerform, it would use it to forward the request
HJ> instead of calling the perform method.
HJ> This would ease development in a lot of projects.
HJ> For example, say I want to validate my visitor on each request. If I had a
HJ> prePerform method I could write a subclass of Action for my project called
HJ> MyProjectBaseAction and include the prePerform method. Inside of
HJ> prePerform, I could do the validation. This would allow me to take the
HJ> validation code out of each one of my specific action classes and never have
HJ> to worry about the validation logic changing. If it did change, I have one
HJ> place to change it instead of 50 or 100.
HJ> James Hicks
--
Best regards,
Anthony
Re: How to keep ActionForm in session from being reset?
Posted by ma...@tumbleweed.com.
One way of resolving this is to have a hidden field in your forms which
specifies which step is being performed. Then in your reset() method, you
can check which step you are at, and reset (or not) fields as appropriate.
--
Martin Cooper
----- Original Message -----
From: "Wilhelm Fitzpatrick" <ra...@well.com>
To: <st...@jakarta.apache.org>
Sent: Friday, August 17, 2001 5:18 PM
Subject: How to keep ActionForm in session from being reset?
> I'm trying to use form beans as suggested in the struts documentation,
> where I use a single form across several actions and pages, accumulating
> data as a I go. Specificially:
>
> I have an Action with constructs the form, prepoulates it with some data,
> then stores it in the session. This action then forwards to .jsp page
> that displays the form, and collects more data. When this form is
> submitted, the whole goes to a third Action that does some processing.
>
> At first, I couldn't get this to work until I figured out that the
> framework is calling reset() on the form bean on each action. So I worked
> around the problem by *not* resent some form fields in the reset call, but
> this seemed like cheating.
>
> Is there are a way in the action mapping to tell the framework *not* to
> reset Form before using it?
>
> -raf
>
>
>
How to keep ActionForm in session from being reset?
Posted by Wilhelm Fitzpatrick <ra...@well.com>.
I'm trying to use form beans as suggested in the struts documentation,
where I use a single form across several actions and pages, accumulating
data as a I go. Specificially:
I have an Action with constructs the form, prepoulates it with some data,
then stores it in the session. This action then forwards to .jsp page
that displays the form, and collects more data. When this form is
submitted, the whole goes to a third Action that does some processing.
At first, I couldn't get this to work until I figured out that the
framework is calling reset() on the form bean on each action. So I worked
around the problem by *not* resent some form fields in the reset call, but
this seemed like cheating.
Is there are a way in the action mapping to tell the framework *not* to
reset Form before using it?
-raf
Re: Suggestion For Action Class
Posted by Wilhelm Fitzpatrick <ra...@well.com>.
On Fri, 17 Aug 2001, Hicks, James wrote:
> I would like to suggest adding a method called prePerform to match each
> perform method in the org.apache.struts.action.Action class and have the
You can do this yourself! just create
public abstract class BaseAction extends Action {
public abstract ActionForward prePreform( ... );
public abstract ActionForward mainPerform( ... );
public ActionForward perform( ... ) {
ActionForward pre = prePerform( ... );
if( pre != null ) return pre;
return mainPerform( ... );
}
}
and then extend all your Action classes from BaseAction instead...
-raf
difference between forward and include?
Posted by Wilhelm Fitzpatrick <ra...@well.com>.
What is the difference between forward and include in the action
mappings? They seem to accomplish the same thing, and the documenation in
the JavaDoc for the ActionMapping classes has the exact same paragraph for
both attributes.
Is there any difference between them?