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:240728
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

Reply via email to