|
From: Keith D. <ke...@in...> - 2005-04-04 05:49:56
|
Steven, All:
The 'validatorMethod' feature discussed below is now implemented and
demonstrated in the 'sellItem' sample in CVS. Specifically:
In the flow definition:
<action-state id="bindAndValidatePriceAndItemCount">
<action bean="sellItemAction" method="bindAndValidate">
<property name="validatorMethod" value="validatePriceAndItemCount"/>
</action>
<transition on="success" to="enterCategory"/>
<transition on="error" to="enterPriceAndItemCount"/>
</action-state>
In SaleValidator, the Validator configured on the 'SellItemAction':
public void validatePriceAndItemCount(Sale sale, Errors errors) {
if (sale.getItemCount() <= 0) {
errors.rejectValue("itemCount", null, "Item count must be
greater than 0");
}
if (sale.getPrice() <= 0.0) {
errors.rejectValue("price", null, "Price must be greater
than 0.0");
}
}
In SellItemAction, which will only perform validation if the
'validatorMethod' property is indeed set:
protected boolean validationEnabled(RequestContext context) {
return containsProperty(VALIDATOR_METHOD_PROPERTY, context);
}
-----Original Message-----
From: Keith Donald [mailto:ke...@in...]
Sent: Sunday, April 03, 2005 1:20 AM
To: 'spr...@li...'
Subject: RE: [Springframework-developer] webflow: FormAction question
Steven,
1.) setupForm is called if and when you want it to be called - with Spring
webflow, you define the workflow explicitly and what actions (or target
methods) should be called on what events. That's the inherent power in web
flows---the action methods don't contain any workflow, they just execute
some logic-- the flow itself fully defines the workflow, dynamically.
Checkout the new 'sellitem' sample in samples/webflow in CVS to see how it
calls 'setupForm' at the beginning of the wizard flow.
2.) You could always do custom validation logic for each page in the action
that processes each submit, in a custom method that you define, like "public
bindAndValidateShippingDetails(RequestContext context)". However, I am
thinking it makes sense to have the FormAction aware of a action property
called 'validatorMethod' that will be invoked by ValidatorUtils, to allow
piecemeal validation of the domain object on a per page basis (instead of
always calling the 'validate' method, which validates the whole object).
Either that or perhaps we need a WizardFormAction that provides specific
support for this. Thoughts?
Keith
-----Original Message-----
From: spr...@li...
[mailto:spr...@li...] On Behalf Of
Steven Devijver
Sent: Saturday, April 02, 2005 4:41 PM
To: spr...@li...
Subject: Re: [Springframework-developer] webflow: FormAction question
Keith,
Thanks for the feedback an my apologies for not posting on the user
list. There's two things that aren't clear to me:
1) is setupForm on FormAction called only once and if so where and why
only there?
2) how can I validate every page/form separately saying this or that
is missing? Every form submit uses the same validator, how can it
validate only the properties related to the form?
Thanks
Steven
On Apr 2, 2005 8:11 PM, Keith Donald <ke...@in...> wrote:
> Hey Steven,
>
> Be sure to use the 'users' list or forum for questions like this next
time,
> so more users will see it.
>
> You can use one FormAction to do this, yep. Erwin will be checking in a
> wizard sample shortly (potentially this evening), so I'll just sum up what
> the sample will illustrate:
>
> - The FormAction already has a 'bindAndValidate' method, that does what
you
> want on each intermediate page submit. So you can have that method called
> on each submit by using a bindAndValidate<X> action state, where <X>
> describes what it is you are binding and validating.
>
> For example:
>
> <action-state id="bindAndValidatePageFoo">
> <action id="myFormAction">
> <property name="executeMethodName" value="bindAndValidate"/>
> </action>
> <transition on="error" to="viewPageFoo"/>
> <transition on="success" to="viewPageBar"/>
> </action-state>
>
> <action-state id="bindAndValidatePageBar">
> <action id="myFormAction">
> <property name="executeMethodName" value="bindAndValidate"/>
> </action>
> <transition on="error" to="viewPageBar"/>
> <transition on="success" to="submit"/>
> </action-state>
>
> <action-state id="submit">
> <action id="myFormAction">
> <property name="executeMethodName" value="submit"/>
> </action>
> <transition on="error" to="error"/>
> <transition on="success" to="end"/>
> </action-state>
>
> Keep in mind I've omitted the view states and end states here, (I also
typed
> this on-the-fly) but this should get you started.
>
> Looking at the definition above, and given this need will be quite common,
> it may be wise for us to make the 'executeMethodName' property a first
class
> citizen in the DTD. Erwin, what do you think? Others? For example:
>
> <action id="myFormAction" executeMethod="submit"/>
>
> That would shorten the above xml a good bit, to:
>
> <action-state id="bindAndValidatePageFoo">
> <action id="myFormAction" executeMethod="bindAndValidate"/>
> <transition on="error" to="viewPageFoo"/>
> <transition on="success" to="viewPageBar"/>
> </action-state>
>
> <action-state id="bindAndValidatePageBar">
> <action id="myFormAction" executeMethod="bindAndValidate"/>
> <transition on="error" to="viewPageBar"/>
> <transition on="success" to="submit"/>
> </action-state>
>
> <action-state id="submit">
> <action id="myFormAction" executeMethod="submit"/>
> <transition on="error" to="error"/>
> <transition on="success" to="end"/>
> </action-state>
>
> It may also be wise to drop "Name" from "executeMethodName", leaving the
> shorter "executeMethod" - as name is sort of implied already anyway...
> (though name is more accurate from a implementation detail POV, but who
> cares about that here.)
>
> What do you think?
>
> Keith
>
> -----Original Message-----
> From: spr...@li...
> [mailto:spr...@li...] On Behalf
Of
> Steven Devijver
> Sent: Saturday, April 02, 2005 12:55 PM
> To: spr...@li...
> Subject: [Springframework-developer] webflow: FormAction question
>
> Hi,
>
> I want to create a wizard that spans across multiple pages. I want to
> bind to one and the same form instance across the different pages and
> validate on every page submit. When the wizard completes I want this
> one instance to contain all the information entered through the
> various forms.
>
> Can I use FormAction for this purpose?
>
> Thanks
>
> Steven
>
> --
> "If you want to be a different fish, you gotta jump out of the school."
> -- Captain Beefheart
>
> -------------------------------------------------------
> SF email is sponsored by - The IT Product Guide
> Read honest & candid reviews on hundreds of IT Products from real users.
> Discover which products truly live up to the hype. Start reading now.
> http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
> -------------------------------------------------------
> SF email is sponsored by - The IT Product Guide
> Read honest & candid reviews on hundreds of IT Products from real users.
> Discover which products truly live up to the hype. Start reading now.
> http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
>
--
"If you want to be a different fish, you gotta jump out of the school."
-- Captain Beefheart
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
Springframework-developer mailing list
Spr...@li...
https://lists.sourceforge.net/lists/listinfo/springframework-developer
|