So you want to create a ModelGlue:Unity application? ( Part 4 )
Previously in this series, we installed the ModelGlue:Unity framework and the ColdSpring framework. We used the ModelGlueApplicationTemplate as the skeleton, added our basic flow and navigation. Finally we can save and list contacts Our Contact-O-Matic is moving right along.
In the last segment, we tested the 'failure' path and were routed back to the form. We also tested the 'success' path and were routed to the contact list. Open the ContactFormBean.cfc located in *ContactManagerMG/Model and edit the validate function (You did check the validate box in the rooibos generator like the last series said, didn't you ;) )
Our validate function should have the returntype of boolean. We will pass in a structure to hold any error messages and check the lengths of our two properties ContactName and ContactType. Your validate function should look like this:
There are no comments for this entry.
Add Comment Subscribe to Comments Good Catch. It is extremely bad form to let a variable leak outside of the intended scope.
I've updated the code so as to reflect the best practice.
I'm going through these for the first time, it makes sense but will take some effort to get really familiar with MVC & OO for me.
I did notice that you used a variable called isValid and although it is var'd I'd still recommend not naming vars after built in CF functions, for code readability if nothing else. Awesome tutorials, I'm learning a LOT
Dan found a small code error
<cfif NOT getContactType() IS 'friend')>
<cfset tempErrors['ContactType'] = "Only friends allow in here." />
</cfif>
should be
<cfif NOT (getContactType() IS 'friend')>
<cfset tempErrors['ContactType'] = "Only friends allow in here." />
</cfif>
I'm going through this tutorial for a second time, now that I have a better idea of Beans and other concepts.
Small question/comment on the function validate() shouldn't the tempErrors be a "var" as in < cfset var tempErrors=structNew() /> ?
If that was intended could you explain why? wouldn't TempErrors be created at the "Variables" level?
Fernando