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>