You know, I gave almost the same question last week on the model-glue mailing list. Kept seeing these real simple samples, but nothing that appeared to work with complex data.
Matt Williams was kind enough to whip out a basic application and place the download on his blog (http://mattw.mxdj.com/sample_servicedaobean_files.htm). Although it doesn't use a total bean/DAO/Gateway architecture (see Ray's series on Model-Glue for more info [http://ray.camdenfamily.com/index.cfm/ModelGlue]), Matt's is still a great, and easy to understand, example of how to handle complex data objects. He also built it without using a framework so that anyone can gain from the examples and apply to whatever methodology they are using for their development. Cutter ______________ http://blog.cutterscrossing.com Steve Brownlee wrote: > Ian, I think this project is a perfect place to start since you're only > dealing with one object and its data. I'll provide my thoughts and > hopefully it will help. > > One thing I want to say is that you're still performing the steps > procedurally, but the data is manipulated as attributes of an object. You > are still going to create a form and then submit to a processing page that > validates everything. How you build the application remains unchanged. > > >> But I can not convert this to an object orientated design. I >> can create a simple object that would represent a trima >> machine which I believe is often called a bean > You're on the right track here. You create the Trima Bean. It simply holds > the attributes and get/set methods for each attribute of a trima machine. > Since the bean's function is to accept and give the data while it's being > manipulated, the validation should be done at this point. > >> I think I understand how one would separate the database >> logic into a DAO. > Correct, the TrimaDAO handles *all* access to the datasource. This is its > only purpose, which is why the data should not be validated here. It has > the CRUD methods [create/read/update/delete]. Each of these methods has one > argument which accepts a Trima Bean which is a struct. > <cfargument name="TrimaBean" type="struct" required="true"> > > So a sample call would be: > trimaDAO = createobject("component", "com.bloodsource.trimaDAO"); > trimaDAO.update(trimaBean); > >> Is it good or bad to put bad >> and/or partial data into the bean because some of the form >> data was good and some was bad? > IMHO, since validation is done by the bean, partial data in one of the > attributes is not acceptable. > >> How does one use a form first to show the current bean data and >> then to show the form submitted data with error feedback? > > FORM PAGE > -------------- > <cfscript> > trimaBean = createobject("component", "com.bloodsource.trimaBean"); > trimaDAO = createobject("component", "com.bloodsource.trimaDAO"); > > trimaBean.setMachineID("64"); > currentTrimaBean = trimaDAO.read(trimaBean); > </cfscript> > > <form action="ProcessTrimaBean.cfm"> > <input type="text" name="PlateletLevel" > value="#currentTrimaBean.getPlateletLevel()#"> > <input type="text" name="BloodType" > value="#currentTrimaBean.getBloodType()#"> > etc... > </form> > > PROCESSING PAGE > ------------------ > <cftry> > <cfscript> > trimaBean = createobject("component", "com.bloodsource.trimaBean"); > trimaDAO = createobject("component", "com.bloodsource.trimaDAO"); > > trimaBean.setPlateletLevel(form.PlateletLevel); > trimaBean.setBloodType(form.BloodType); > etc... > > trimaDAO.update(trimaBean); > </cfscript> > <cfcatch> > <cfset alertMessage = trimaBean.invalidDataMessage> > -- DISPLAY ERROR INFORMATION HERE -- > </cfcatch> > <cftry> > > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Message: http://www.houseoffusion.com/lists.cfm/link=i:4:240733 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

