struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dave Newton <davelnew...@gmail.com>
Subject Re: S1: Problem overriding processValidate() from RequestProcessor
Date Fri, 17 Sep 2010 22:28:04 GMT
I'm skeptical--does the superclass throw an exception?

On Fri, Sep 17, 2010 at 6:26 PM, Oscar <oscar.kalderon@gmail.com> wrote:

> But i understand that, if there are validation errors, in this line:
>
> boolean resValidacion = super.processValidate(request, response, form,
> mapping);
>
> resValidacion will be false, but instead that looks like the execution
> breaks in that point and redirects to input
>
> 2010/9/17 Dave Newton <davelnewton@gmail.com>
>
> > ...
> >
> > Of course you can execute code after that.
> >
> > *You're* executing code after that--but when there are validation errors
> > the
> > code you'll execute is the check to see if there were validation errors
> and
> > the type check.
> >
> > On Fri, Sep 17, 2010 at 5:51 PM, Oscar <oscar.kalderon@gmail.com> wrote:
> >
> > > But doesn't exist a way to do that? I mean, execute
> > super.processValidate()
> > > and execute code after that? Because it will be useful to prepare stuff
> > > after you do something in the action, for example, insert something in
> > the
> > > action and after prepare a list of items or something like that.
> > >
> > > 2010/9/17 Dave Newton <davelnewton@gmail.com>
> > >
> > > > You only call prepareAfter if there aren't validation errors--if
> there
> > > are,
> > > > it won't be called.
> > > >
> > > > On Fri, Sep 17, 2010 at 4:48 PM, Oscar <oscar.kalderon@gmail.com>
> > wrote:
> > > >
> > > > > Hi to all. I'm working on a project using Struts 1.1 because those
> > are
> > > > > client requirements. I override RequestProcessor and some of it's
> > > > methods.
> > > > > like processRoles, processActionPerform, and so on. I want to
> > implement
> > > a
> > > > > logic like Struts 2 Preparable interface, where if you implement
in
> > > your
> > > > > Struts 2 Action you implement method prepare() that executes before
> > an
> > > > > action method is called.
> > > > >
> > > > > I want to simulate that in Struts 1 so i created a PreparedForm
> where
> > i
> > > > > define 2 methods signature: prepareBefore and PrepareAfter.
> > > prepareBefore
> > > > > will execute before action is called and prepareAfter until after
> > > action
> > > > > call.
> > > > >
> > > > > This is PreparedForm:
> > > > >
> > > > > public interface PreparedForm {
> > > > >
> > > > >    public void prepareBefore(HttpServletRequest request);
> > > > >
> > > > >    public void prepareAfter(HttpServletRequest request);
> > > > > }
> > > > >
> > > > > This is a form that implements PreparedForm:
> > > > >
> > > > > public class PaisForm extends DefaultActionForm implements
> > PreparedForm
> > > {
> > > > >
> > > > >    private String idpai;
> > > > >    private String idmon;
> > > > >    private String nombre;
> > > > >    private String codigoNomina;
> > > > >
> > > > >    public void prepareAfter(HttpServletRequest request) {
> > > > >        //Do stuff after execute action method
> > > > >    }
> > > > >
> > > > >    public void prepareBefore(HttpServletRequest request) {
> > > > >        //Do stuff before execute action method
> > > > >
> > > > >    }
> > > > > ...
> > > > >
> > > > > So, i override processValidate to call here prepareAfter in case
> that
> > > > form
> > > > > validation has errors, but maybe i didn't overrided well the
> method,
> > > this
> > > > > is
> > > > > my method:
> > > > >
> > > > >  protected boolean
> > > processValidate(javax.servlet.http.HttpServletRequest
> > > > > request,
> > > > >
> >  javax.servlet.http.HttpServletResponse
> > > > > response,
> > > > >                                  ActionForm form,
> > > > >                                  ActionMapping mapping)
> > > > >                           throws java.io.IOException,
> > > > >                                  javax.servlet.ServletException {
> > > > > boolean resValidacion = super.processValidate(request, response,
> > form,
> > > > > mapping);
> > > > >        //Si se implemento PreparedForm, se llama prepareAfter
> > > > >        if (form instanceof PreparedForm && !resValidacion)
> > > > >            ((PreparedForm)form).prepareAfter(request);
> > > > >
> > > > >        return resValidacion;
> > > > >    }
> > > > >
> > > > > When i call an action and validate() in this line:
> > > > >
> > > > > boolean resValidacion = super.processValidate(request, response,
> > form,
> > > > > mapping);
> > > > >
> > > > > returns validation errors, it returns me directly to jsp and
> doesn't
> > > > > continue on the next lines and i don't know why.
> > > > >
> > > > > Thanks in advance.
> > > > >
> > > > >
> > > > > --
> > > > > Oscar Calderón
> > > > > SCJP 6  <http://javahowto.net>
> > > > >
> > > >
> > >
> > >
> > >
> > > --
> > > Oscar Calderón
> > > SCJP 6  <http://javahowto.net>
> > >
> >
>
>
>
> --
> Oscar Calderón
> SCJP 6  <http://javahowto.net>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message