RE: [coldbox:3235] Re: How to invoke a method in the containing event handler, from within a plugin?

Passing this data to the RC seems like a rigged up way of handling my
situation.

Yeah. The problem is it is not a true 'event', being private and all.

I am trying to make things more easy on myself to avoid a lot of
redundant behavior... and it is starting to be a big pain =) haha.

I planning an approach to try an Interceptor+Plugin combination for my
BO validators which happens before any of my generic form processing
handlers fire... my interceptor would control event flow based on the
results of the validation...

I have yet to started coding this specifically, so I have no idea how
it all would work for you.. but a similar approach might suitable for
your needs...

Anyone have thoughts on this?

I was thinking interceptors myself as well... except I don't know
understand the workflow of them good enough yet. At the moment, this
form plugin that I have takes care of validation and rendering through
configuration.

I set the validation in the handler and have a few methods for
determining if the form is "OK" to which I can then interact with the
models appropriately, then this plugin gets set in the RC and passed
to the view, of which the entire form is rendered through
configuration.

My initial plans I set the validation rules in the view as well, and I
wanted to use some type of interceptor to traverse backwards ie
preProccess to tell the handler that the form was OK, but no such
luck.

Generally, it looked like this: <cfinvoke component="#local.form#"
method="textbox" name="test" default="asdf" maxlength="23"
validation="required,valid_email,min_length[20]">

The idea behind this, aside from rendering, is to automatically set
some validation rules as well. For instance, in this one since the
maxlength field is set, it will automatically set a validation rule of
max_length[23]. As well, if it finds the word required in the list of
rules, it will automatically put a asterisk next to the label.

As it stands, this hole handler specific validation is the only issue
I have left running. I think I am going to go with the UDF includes
though.

I just have to say this, real quick. I would strongly urge anyone and everyone to never handle validation in your controller (event handler in ColdBox). Aside from this simply being the entirely wrong place to do this work, you will find yourself spiraling out of control as your application grows and expands. I know this from personal experience because years ago when I first crossed over into the whole MVC world, that is what I did. I promise you, it’s a disaster.

In my opinion, the controller should have absolutely zero knowledge about validation, and validation should have absolutely zero knowledge about the controller. The controller should simply pass off the request data to another entity and receive a boolean response, which it (the controller) will use to direct traffic in the appropriate direction. The most common approach to make this a reality is to utilize a service layer. Here’s an example from a contact form submission controller:

if ( getContactService().createContact(params: event.getCollection()) ) { // redirect to success message } else { // redirect to error message }

In this example, the controller knows absolutely nothing. All it does is direct traffic based upon a result. And that is exactly what your controller should do. Nothing more. Nothing less.

Now then, exactly where should you actually handle your validation? You will probably get lots of different answers to that question. Some will say in the service. Some will say in the business object. Some will say in a separate validation object. I say the business object. It can (and should) utilize helper object(s) to do the heavy lifting, but it should absolutely be up to the business object to know whether or not it is in a valid state.

I don’t have the time to go into all of the ins and outs of what I mean or how I handle that, so I will just refer you to an old blog post of mine in which I discuss the validation framework that Paul Marcotte and I wrote for Paul’s Metro framework.

http://www.quackfuzed.com/index.cfm/2009/2/27/Validating-Business-Objects-with-Metro

HTH

(Hmmmm, I guess it wasn’t so “real quick” after all.)

I guess that is part of what I am trying to accomplish here with my
little form plugin. The only difference is, It takes 1 hole line to
set the validation on the form.

<cfset local.form.setValidation('field', 'Field Label',
'required,min_length[23],customValidationFunction')> and this is done
in the handler.

then a

<cfif local.form.doValidation()>
<!--- process stuff --->
</cfif>

I have done MVC before within CI on some pretty massive apps, and have
always used validation in the context of the event. Then again, I
break a lot of handlers down to a very specific tasks. Very rarely
will a handler of mine have more then 5-6 events.

Validation in your controller is a horrible idea, always, but especially if you are trying to work in objects, which I am assuming that you are since ColdBox is an object oriented framework. However, it is your application and you are certainly entitled to architect it in whatever manner you see fit. Just keep in mind that you are working with a framework that is designed to be object oriented, and the advice that you are being given (by everyone) is to separate the concerns into the correct objects.

/me bows out gracefully