[Opensource] Struts Validation in Expresso
Raul DAVIDOVICH
R.DAVIDOVICH at caconcology.com
Fri May 28 02:55:59 PDT 2004
Hello,
I'm implementing Struts' form validation so it can be performed
transparently to the developer. I more or less decoded how it works (more
less than more) and modified the request processor and the validation
plugin so expresso's DefaultForm can be used. Up to here this works if we
manually call the validate() method in the handle state, and manually
transitionback to the prompt state. Now, I'm stuck on automatically
forwarding back to the prompt state if the form is invalid.
Peter Pilgrim suggested to "cache" the prompt state somewhere like the
session, and retrieve the name of the controller from the
struts-config.xml, and then reconstruct the URL
"context/Something.do?state=promptState"
here is what I did:
Controller.java
...
public ControllerResponse newState(String newState,
ControllerRequest myRequest)
throws ControllerException,
NonHandleableException {
..
//added to help struts validator to find the state to go back to if
an error is found in the form
PersistentSession mySession = myRequest.getSession();
//is it a good idea to reset it systematically, or just a waist of
proc cycles?
mySession.removePersistentAttribute("previousState");
//to avoid issues in the struts-config.xml maybe the name of the
controller could also be cached?
mySession.setPersistentAttribute("previousState", newState);
return cr;
} /* newState(String) */
...
ExpressoRequestProcessor.java
...
protected boolean processValidate(HttpServletRequest request,
HttpServletResponse response,
ActionForm form,
ActionMapping mapping)
throws IOException, ServletException {
...
String input = StringUtil.notNull(mapping.getInput()+"?state="
+request.getSession().getAttribute("previousState").toString());
//up to here it goes OK. the URL is correct.. I didn't find out how to get
the context path
...
if (moduleConfig.getControllerConfig().getInputForward()) {
ForwardConfig forward = mapping.findForward(input);
processForwardConfig( request, response, forward);
}
//usually it goes in here since there is no ForwardConfig in Expresso
else {
internalModuleRelativeForward(input, request, response);
}
//but even with the right input URL it still forwards to the state and
controller defined with the action and transition button
//the controller and state coded in the request remain unchanged, and I
didn't find out how to change them
return (false);
}
...
any clues?
Best regards,
---------------------------------------------------
Raul Davidovich
Responsable Informatique
Cvitkovic & Associés Consultants
(33) 1 45 15 40 68
(33) 1 45 15 40 41 Fax
-------------------------------------------------------
http://www.caconcology.com
More information about the Opensource
mailing list