Hi,

In my applications, if a user sends invalid data, I like to let them know
about all of the problems at once rather than one by one.

So for example, after submitting a form, a user may get a msg like this:
- Please make sure your TITLE is less than 25 characters long.
- Please provide your age in integer format.
- Please choose a price in numerical format.

To handle this, I have a MSG CFC that stores the relevant messages of the
current request.

The process looks something like this:
1. User sends data

2. Validate customer details, update MSG component with any errors 

3. Validate order details, update message component with any errors 

4. If there are any errors, display messages and abort

My question is where and how should the MSG CFC be instantiated? You will
notice that almost all my other CFC's use it, so should I create a new MSG
CFC in each of them? Or should I just create a main one and pass it in to
each CFC every time?

Example A (Pass in one MSG CFC)
1. MsgCFC=createobject('component','Msg').init()

2. Customer.Validate(MsgCFC) - updates MsgCFC by reference 

3. Order.Validate(MsgCFC) - updates MsgCFC by reference 

4. ....

OR

Example B (Create a new MSG CFC in each object) 
1. MainMsgCFC=createobject('component','Msg').init()

2. Customer.Validate() - another MsgCFC is created inside Customer 

3. MainMsgCFC.Merge(Customer.getMSG()) - merge customer MSGs with MainMsgCFC


4. Order.Validate() - another MsgCFC is created inside Customer 

5. MainMsgCFC.Merge(Order.getMSG()) - merge order MSGs with MainMsgCFC 

6. ....

Example A seems cleaner and more proper, but I am not that comfortable
having every single one of my CFCs rely on another component as an argument.
Also in example B I have the choice to merge the messages or not. Sometimes
I want to suppress error messages for a certain component. I guess this can
be achieved as well in Example A by creating a new MSG object for each
validating CFC, passing it in and then merging the result back to the main
MSG CFC, but all of a sudden the solution isn't so clean anymore.

So basically it comes down where the MSG component should be declared,
inside or outside the related CFCs?  What do you think? How do you guys/gals
handle messages from components?
 
Cheers,

Baz





----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to 
[email protected] with the words 'unsubscribe cfcdev' as the subject of the 
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
(www.cfxhosting.com).

An archive of the CFCDev list is available at 
www.mail-archive.com/[email protected]


Reply via email to