Thanks to the help earlier, I have almost the entire front-end of the
application I'm
working on up and running. However, I'm now working on ensuring it can handle
bad data,
such as folks playing with the URL or accessing an old URL for a category that
may not
exist anymore for the standard drill down list. In normal ColdFusion, the final
line of
"defense" is a try/catch around an invoke, in case of data type mismatches. If
it fails,
it would redirect to another page or give an error message, depending on the
page.
With the Mach-II version of the application, if there is invalid data, such as
a
non-numeric ID or non-existent ID being passed, how to I look for and handle
this and
where? In the listener, the gateway, the DAO? I tried using announceEvent, but
that caused
errors with the return type not being of the right type. Would it be better to
not return
the bean directly but put it in a structure with a result code so its always
the right
type, or am I missing something else? I already have the DAO set to return true
or false
if the bean is populated instead of the bean itself. Really need to figure this
out as we
are required to have all of our apps deal with this without giving any
informative error
messages before they can go production.
For an example of one place I'm trying to do this, is the CategoryDetails page
that loads
when you click a category name.
~~~Snippet from the Mach-II XML~~~
<event-handler event="CategoryDetails" access="public">
<notify listener="categoriesListener" method="getCategoryDetail"
resultArg="categoryBean"
/>
<notify listener="factsheetsListener" method="getSheetsInCat"
resultArg="qSheetsByCategory" />
<view-page name="header" />
<view-page name="categorydisplay" />
<view-page name="footer" />
</event-handler>
~~~~categoriesListener.cfc~~~~
<cfcomponent name="CategoryListener" displayname="CategoryListener"
output="false"
extends="MachII.framework.Listener">
<!--- Configures this listener as part of the Mach-II framework --->
<cffunction name="configure" access="public" output="false" returntype="void">
<!--- one time deal with our DAO and Gateway --->
<cfset myDSN = getProperty("dsn") />
<cfset variables.categoryDAO = createObject("component", "CategoryDAO").init(
DSN =
myDSN ) />
<cfset variables.categoriesGateway = createObject("component",
"categoriesGateway").init( DSN = myDSN ) />
</cffunction>
<!--- returns the query recordset returned by the Category Gateway --->
<cffunction name="getCategoryList" access="public" output="false"
returntype="query">
<cfreturn variables.categoriesGateway.getAllCategories() />
</cffunction>
<!--- Gets detail on a single Category --->
<cffunction name="getCategoryDetail" access="public" output="false"
returntype="Category">
<cfargument name="event" type="MachII.framework.Event" required="true" />
<cfset var category = createObject("component", "Category").init( CategoryID
=
arguments.event.getArg("whichcategory") ) />
<cfset variables.categoryDAO.read(category) />
<cfreturn category />
</cffunction>
</cfcomponent>
~~~~Snippet from CategoryDAO.cfc~~~~
<cffunction name="read" access="public" output="false" returntype="boolean">
<!--- the bean to populate? --->
<cfargument name="Category" type="Category" required="true" />
<cfset var queryCategories = "" />
<!--- Make sure Category requested is a valid number --->
<cfif val(arguments.Category.getCategoryID()) GT 0>
<!--- run the query based on the ID loaded from the Listener function --->
<cfquery name="queryCategories" datasource="#variables.DSN#">
SELECT categoryid, categoryname, description, range
FROM categories
WHERE categoryid = <cfqueryparam
value="#arguments.Category.getCategoryID()#"
cfsqltype="cf_sql_integer" />
</cfquery>
<!--- re-initialize the bean with data from the query --->
<cfset arguments.Category.init( CategoryID = queryCategories.categoryid,
CategoryName = queryCategories.categoryname,
Description = queryCategories.description,
Range = queryCategories.range ) />
<cfreturn true />
</cfif>
<cfreturn false />
</cffunction>
Thanks in advance,
Summer S. Wilson
Collectonian on Yahoo! Messenger ~ Facebook
(http://www.facebook.com/Collectonian)
An Eclectic World (http://eclectic-world.com) ~ LiveJournal
(http://collectonian.livejournal.com)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to Mach-II for CFML list.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/mach-ii-for-coldfusion?hl=en
SVN: http://greatbiztoolsllc.svn.cvsdude.com/mach-ii/
Wiki / Documentation / Tickets:
http://greatbiztoolsllc.trac.cvsdude.com/mach-ii/
-~----------~----~----~----~------~----~------~--~---