It all depends on how complex you want things to be. In general, If you're
validating form input, I wouldn't do it at the DAO or Gateway level at all.
I'd create a separate validator object for the form, and give it a few
methods:
CustomerFormValidator
init() - create a new CustomerFormValidation object
validate( formFields ) - perform the validation and populate the internal
error fields if necessary
isValid() - return true if the form inputs checked by validate are valid
getValidationErrors() - returns an array of strings which list the errors.
getValidCustomerObject() - returns a model of the customer object with the
valid data
After doing this, in my listener, I'd do the following:
var validator = CreateObejct("component","CustomerFormValidator").init();
validator.validate( event.getArgs() );
if( validator.isValid() ) {
try {
getCustomerService().addCustomer( validator.getValidCustomerObject() );
announceEvent("success");
} catch( ValidationError error ) {
event.setArg("arrDatabaseErrors",[error.message]);
announceEvent("databaseFailure");
}
} else {
event.setArg("arrValidationErrors",validator.getValidationErrors());
announceEvent("validationFailure");
}
There's a couple different ways you could implement the
CustomerFormValidator.
Adam Ness
On Wed, Jun 17, 2009 at 6:11 PM, Teaman <[email protected]> wrote:
>
> I writing my first action filter for a form submission. When an error
> in data entry is detected for example, how is the error msg handled?
> I assume you simply return false on the DAO or Gateway method called
> by the listener. But if a variety of error conditions are possible,
> such as missing field entry or input too long or file already exists,
> etc... I'd think this info would need to be passed back too.
>
> Can someone please explain how this is normally handled?
> Where is the error msg text normally specified? Only in the View?
> Currently my view file is planning to look for an error msg in the
> event obj. So somewhere it's got to be put into the event obj. Is
> that with a putArg? Where is that call usually made?
>
> This is the biggest struggle I have with learning Mach-II. I don't
> know where to put the code. If you consider each of the code snippet
> locations as "buckets" (the config .xml file event-handler, the
> listener, the filter, the gateway, the view, the model, etc.) it's
> sometimes hard to know where to put some piece of the code.
> Particularly a variable... like a parameter or property. Do I set it
> in the Properties section, or in the event-handler or in the filter/
> listener or in the component or in the method??? Are there "rules of
> thumb" to follow?
>
> I guess this is really two threads in one. Sorry... being effficient.
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to Mach-II for CFML list.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/mach-ii-for-coldfusion?hl=en
SVN: http://greatbiztoolsllc.svn.cvsdude.com/mach-ii/
Wiki / Documentation / Tickets:
http://greatbiztoolsllc.trac.cvsdude.com/mach-ii/
-~----------~----~----~----~------~----~------~--~---