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 21:22:24 GMT
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>
>

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