Réf. : Re: [Opensource] Struts Validation in Expresso
Peter A. Pilgrim
peterp at xenonsoft.demon.co.uk
Thu Mar 18 19:07:56 PST 2004
Raul DAVIDOVICH wrote:
>
> Peter,
>
>
>
>>>I presume you are allowing the Struts MVC to automatically the validate
>>>the action form bean in the struts-config.xml file.
>
>
> Exactly
>
>
>
>>>Have you tried making it work manually inside an Expresso Controller?
>>>Get the ActionForm from the `ServletControllerRequest'. I believe the
>
> method
>
>>>is:
>>>org.apache.struts.action.ActionForm getForm()
>>> Gets the action form as a convenience for pure Struts writer.
>
>
>>>then call validate() on the form bean.
>
>
>>>ActionErrors errors = formBean.validate( httpServletRequest,
>
> actionMapping );
>
>
>>>See also
>
>
>>>HttpServletRequest getHttpServletRequest()
>>> Gets the http servlet response object Important: A Controller
>
> should only use this
>
>>>method if strictly necessary, and not write output that is otherwise able
>
> to be handled with
>
>>>inputs, outputs and transitions.
>
>
>>>org.apache.struts.action.ActionMapping getMapping()
>>> Gets the action mapping as a convenience for pure Struts
>
> writer.
>
> Yes. it works.
>
>
>
>
> In fact, I have the validation working correctly. I modified
> ExpressoRequestProcessor overriding the processValidate() method so custom
> logic can be performed there.
> Normally, in pure Struts, the mapping is done one input -> one action. This
> input is either a JSP or an action mapping (/something.do), and
> RequestProcessor forwards back to it if the validation fails.
>
> In Expresso an action mapping maps to a controller, with many states, so we
> have many inputs -> many states, and the input comes usually from a prompt
> state.
>
> So my problem is: how to get the prompt state in the processValidate()
> method so we can forward back to it if validation fails, and keep it as
> transparent as possible to the developer.
>
> 1) is it cached somewhere? if it is, how could I retrieve it?
> if not,
I am not sure if this is cached anywhere.
> 2)would it be clean to cache it somewhere? (like the session for
> instance)
The place to look would be
`com.jcorporate.expresso.core.controller.Controller.java'
If you can store the original state in the request or session scope to
jump back to, then it would help in the reconstruction of a URL forward.
> 3)would it be better to define the input parameter in struts-config.xml
> as input="promptState, controller.of.prompState, processState;
> promptOtherState, OtherController, anotherProcessState", somewhat similar
> to workflow definitions in controllers
> 4)can a different option be to define it in a separate XML config file?
> or customizing config.xml or validation.xml?
>
>
> this is the original code where it forwards back to the input:
> ...
> if (moduleConfig.getControllerConfig().getInputForward()) {
> ForwardConfig forward = mapping.findForward(input);
> processForwardConfig( request, response, forward);
> } else {
> internalModuleRelativeForward(input, request, response);
> }
> ...
>
Yes this would not work for Expresso and neither for Struts if you
used the `DispatchAction' or `LookupDispatch'. The only way I think
it can be down cleverly without modification of the frameworks
would be to :
1) Add an "originalPromptState" parameter to the HTML Form
use that to store the invocation to the promptX state method.
<form action="someUrl" >
<input type="hidden" name="originalInvocationState" value="promptSellDvd" />
</form>
2) Dont really on Struts framework auto invalidate form entry mode
3) Write Expresso Framework controller utility to handle
invalid Struts forms. A method that will retrieve the
"originalInvocationState" from request scope
and construct the forward dispatch URL. e.g
"acme/salesController.do?state=promptSellDvd"
displays the sales DVD order form again.
--
Peter Pilgrim
__ _____ _____ _____
/ //__ // ___// ___/ + Serverside Java
/ /___/ // /__ / /__ + Struts
/ // ___// ___// ___/ + Expresso Committer
__/ // /__ / /__ / /__ + Independent Contractor
/___//____//____//____/ + Intrinsic Motivation
On Line Resume
||
\\===> `` http://www.xenonsoft.demon.co.uk/no-it-striker.html ''
More information about the Opensource
mailing list