Galleon Forum Ports Comparisons

Where's My Product?

back

Here are some samples of how you might fetch data for a single product across three related events in each framework. Each example assumes that the model is the same and that information for the individual Product is returned as a bean from an Application.ProductService object via a getProduct() method that accepts one productid argument. The affected code is highlighted in each example:

ColdBox (9 lines, 3 config points)
/handlers/storeAdmin.cfc
<cffunction name="needProduct">
	<cfargument name="event" required="true" />
	<cfset var rc = event.getCollection() /> 
	<cfparam name="rc.productid" default="" /> 
	<cfset rc.product = Application.ProductService.getProduct(rc.productid) />
</cffunction>

<cffunction name="productDetail"> 
	<cfargument name="event" required="true" /> 
	<cfset needProduct(event) />
	<cfset event.setView("product/detail") /> 
</cffunction> 

<cffunction name="productEdit">
	<cfargument name="event" required="true" /> 
	<cfset needProduct(event) />
	<cfset event.setView("product/form") /> 
</cffunction>

<cffunction name="productSave">
	<cfargument name="event" required="true" />
	<cfset var rc = event.getCollection() /> 
	<cfset needProduct(event) />
	... save the product ... 
	<cfset setNextEvent("Handler.Event"[,"query_string=parameters"]) />
</cffunction>
Fusebox (traditional) - 7 lines, 3 config points
/model/store/circuit.xml
<fuseaction name="getProduct" /> 
	<set name="attributes.productid" value="" overwrite="false" /> 
	<set name="product" value="#application.ProductService.getProduct(attributes.productid)#" /> 
</fuseaction>
/controller/storeAdmin/circuit.xml
<fuseaction name="productDetail">
	<do action="storeModel.getProduct" />
	<do action="storeView.productAdmin" /> 
</fuseaction>

<fuseaction name="productEdit">
	<do action="storeModel.getProduct" />
	<do action="storeView.productEdit" /> 
</fuseaction>

<fuseaction name="productSave">
	<do action="storeModel.getProduct" />
	<do action="storeView.productSave" /> 
</fuseaction>

FuseBox (CFC): only minor differences from ColdBox above

Mach-II (7-lines, 3 config points)
/listeners/storeListener.cfc
<cfcomponent output="false">
	<cffunction name="configure" output="false">
		... configure the listener ...
	</cffunction>
	
	<cffunction name="getProduct" access="public" returntype="any" output="false">
		<cfargument name="event" type="MachII.framework.Event" required="true" />
		<cfreturn application.ProductService.getProduct(event.getArg("productID")) />
	</cffunction>
</cfcomponent>
/config/mach-ii.xml
<!DOCTYPE mach-ii PUBLIC "-//Mach-II//DTD Mach-II Configuration 1.5.0//EN" "http://www.mach-ii.com/dtds/mach-ii_1_5_0.dtd" >
<mach-ii version="1.5">
	<listeners>
		<listener name="storeListener" type="mii.listeners.storeListener" />
	</listeners>
	
	<event-handlers>
		<event-handler event="productAdmin" access="public">
			<notify listener="storeListener" method="getProduct" resultArg="product" />
			<view-page name="productAdmin" />
		</event-handler>
		
		<event-handler event="productEdit" access="public">
			<notify listener="storeListener" method="getProduct" resultArg="product" />
			<view-page name="productForm" />
		</event-handler>
		
		<event-handler event="productAdmin" access="public">
			<notify listener="storeListener" method="getProduct" resultArg="product" />
			<redirect url="index.cfm?event=productAdmin" persistArgs="productid" />
		</event-handler>
	</event-handlers>
</mach-ii>
Model-Glue (7 lines, 3 config points)
/controller/store.cfc
<cfcomponent displayname="store" extends="ModelGlue.unity.controller.Controller" output="false">
	<cffunction name="getProductFromService" access="private" output="false">
		<cfargument name="productid" type="string" required="true" /> 
		<cfreturn Application.ProductService.getProduct(arguments.productID) />
	</cffunction>
	
	<cffunction name="getProduct" access="public" output="false">
		<cfargument name="event" type="any">
		<cfset event.setValue("product",getProductFromService(event.getValue("productid"))) />
	</cffunction>
	
	<cffunction name="saveProduct" access="public" output="false">
		<cfargument name="event" type="any">
		<cfset var product = getProductFromService(event.getValue("productid")) />
		... save the product ...
	</cffunction>
</cfcomponent>
/config/ModelGlue.xml
<modelglue>
	<controllers>
		<controller name="store" type="glu.controller.store">
			<message-listener message="needProduct" function="getProduct" />
			<message-listener message="saveProduct" function="saveProduct" />
		</controller>
	</controllers>
  
	<event-handlers>
		<event-handler name="productAdmin">
			<broadcasts>
				<message name="needProduct" />
			</broadcasts>
			<views>
				<include name="body" template="product/admin.cfm" />
			</views>
		</event-handler>
		
		<event-handler name="productAdmin">
			<broadcasts>
				<message name="needProduct" />
			</broadcasts>
			<views>
				<include name="body" template="product/admin.cfm" />
			</views>
		</event-handler>
		
		<event-handler name="productAdmin">
			<broadcasts>
				<message name="saveProduct" />
			</broadcasts>
			<views>
				<include name="body" template="product/admin.cfm" />
			</views>
		</event-handler>
	</event-handlers>
</modelglue>

onTap (2 lines, 1 config point)

/_components/store/admin/product/_local/100_store.cfm
<cfparam name="attributes.productid" default="" />
<cfset product = Application.ProductService.getProduct(attributes.productid) />
/_components/store/admin/product/detail/_process.cfm
<cfinclude template="/inc/storeadmin/productdetail.cfm" />
/_components/store/admin/product/edit/_process.cfm
<cfinclude template="/inc/storeadmin/productform.cfm" />
/_components/store/admin/product/edit/save/_process.cfm
... save the product ... 
<cfset tap.goto.href = "detail.cfm" />