Hi Jamo Here is just a few of my ideas on your proposed structure.
tempForm.cfc - this to me seems like something similar to idea of a 'form bean' that is used in the Mach-II framework. Encapsulating the form post is a good idea. However I would rather than do this make each separate form (or form part) a separate cfc so you might have: userAccount.cfc address.cfc make these objects behave like a bean eg getProperty, setProperty methods. When you submit the form, fill each object by calling the setProperty() methods that apply. This is also where I would do any validation on the data. So if you had say address.cfc with a method setPostCode() and someone entered '90210' (5 digit number, 4 digit number is correct in australia) you would throw an exception here back to your controller (cfm page or cfc that's accepting the form post) with a validation exception. Its then up to your controller (maybe your using mach-ii or fusebox or not doesn't matter) to choose the next view to display if an exception occours. Your validator.cfc is not a bad idea. You could probably abstract some of the common validation you do in each setProperty() method into this validator class. Error.cfc I really prefer to throw exceptions rather than build an error object. But that's just cos it fits into the framework we use (fusebox4 with cfc-based model). Think about what you want to do each time you get an error. If its just about displaying an error message back to the user. Is a cfc overkill for this situation? On the other hand if you need to do extensive logging maybe a cfc is usefull. Depends on your application and/or framework. ElementBuilder.cfc You will really limit yourself if you use dynamic form building via cfc's without carefull planning. What if you want to change the way your forms look? You could pass in some parameters I guess about css styles What if you want to redesign a site built using asp? If you leave your forms as html/cfm pages you would only need to change your action pages rather than re-building the whole front end. Also, think about the ideal situation when you get a flower-power design type person in to build your pretty html front ends for you. They probably only have a limited knowledge of CF let alone cfc's. IMO I would leave your forms as html. But by all means build an OO based back end. My 2c Pat -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jamie Lawrence Jenner Sent: Wednesday, 28 July 2004 8:33 PM To: CFAussie Mailing List Subject: [cfaussie] the big oo train, on the right track? hi all, I am just setting out on the OO express (couldnt find any oo books for cf, so im using action script book instead!), so i thought i would create a group of cfcs, whcih will create a form dynamically, validate and return any errors automatically so i dont have to keep binding errors and data back to the form. I currently have 4 objects. tempForm.cfc This creates a copy of the form data values on re post, which, if any errors are found, are bound to the form elements when displayed to the user ElementBuilder.cfc Wherever i want a form element, i invoke the makeformelement function (below) and the function returns a html string of the form element required. n.b During this stage, if the error object is initialised (signifying a re post and the validator finding an error) then the form values are taken from tempform, instead of the values passed (session.myName) #application.formbuilder.makeFormElement("name","text",20,50,session.myName) # Validator.cfc This is passed the arguments collection:form, and then validates each form element based upon a prefix it is given s_=string, n_=numeric etc. Errors.cfc If the validator finds any problems then the error object is initialised, and gets passed the error and field name etc to display to the user This just a very brief explanation, but am i on the right track? Should all of the above be bundled into one cfc as they are all working on the same object (theform). Is this an ok use of a cfc function (elementbuilder cfc) or should this really be done with a custom tag? Personally, as the function is returning 1 value, it seems ok. just after some views on it thats all. I havent got any cf chums you see, my friends work on the dark side (asp.net), cfug in uk is not very good :-( Also, if OO programming is the future, then why arent there any books for cf out there. I have many books on cf, and each one has about two pages on oop, "this is an object, this a class", but they really dont explain the real benefits of oop, and how cf fits in. i spent a year learning how ot program in cf (the traditional way) and it was only once i found cfaussie that i found there was a better way! The right way! the OOP way! But if there had been a book out there on oop when i took up cf, then i would have got it then, and be good at it now! Sorry went off on one there! cheers in advance! jamo --- You are currently subscribed to cfaussie as: [EMAIL PROTECTED] To unsubscribe send a blank email to [EMAIL PROTECTED] Aussie Macromedia Developers: http://lists.daemon.com.au/ --- You are currently subscribed to cfaussie as: [EMAIL PROTECTED] To unsubscribe send a blank email to [EMAIL PROTECTED] Aussie Macromedia Developers: http://lists.daemon.com.au/
