300 likes | 407 Views
An Introduction to Fusebox 4. If written directions alone would suffice, libraries wouldn't need to have the rest of the universities attached. —Judith Martin (aka "Miss Manners"). State of Fusebox. The last two years have seen: increased corporate acceptance of Fusebox
E N D
An Introduction to Fusebox 4 If written directions alone would suffice, libraries wouldn't need to have the rest of the universities attached. —Judith Martin (aka "Miss Manners")
State of Fusebox • The last two years have seen: • increased corporate acceptance of Fusebox • increased developer acceptance of Fusebox • increased demand in job postings for Fusebox • no new version of Fusebox…
Fusebox: What's in it for the client? • Less risk in software projects • Greater "project visibility" • Not locked into a non-standardized framework
Fusebox: What's in it for managers? • Reduces costs of deployment • Reduces cost of tools and training • Allows better allocation of resources
Fusebox: What's in it for me? • Helps good programmers produce great results • Lets you distinguish yourself from your competition • Helps stop the madness
FB4: It's all new! • XML file defines overall application parameters: Fusebox.xml • XML file defines individual circuits: Circuit.xml • a permissions attribute for fuseactions • Plugins allow developer extensions of core Fusebox • Content components • Change in way layouts are handled • Parsing cycle
FB4: It's just the same! • Core files process a fuseaction request • Circuits provide logical groupings of fuseactions • Fuses hold the code • dsp for display • act for action • qry for query • lay for layout
Write Fusedocs • Omitted here for space
Write fuses: qryAllUsers.cfm <cf_querysim> AllUsers userID,firstName,lastName,newsletters 100|Stan|Cox|19 200|Haywood U.|Buzzoff|5 300|Marge|Inoferror|11 </cf_querysim>
Write fuses: dspUserList.cfm <h2>User List</h2> <table border="0"> <cfoutput query="AllUsers"> <tr> <td><strong><a href="#self#?fuseaction=#xfa.editUser#&userID=#userID#">#lastName#</a></strong>,#firstName#</td> </tr> </cfoutput> </table> <br> <cfoutput> | <a href="#self#?fuseaction=#xfa.newUser#">New user</a> | </cfoutput>
Write fuses: qryNewsletters.cfm <cf_querysim> Newsletters newsletterID,newsletterName 1|Journal of Misanthropy 2|Today's Mendicant 4|Spotlight on Great Managers 8|WaffleWorld 16|GeekWeek </cf_querysim>
Write fuses: qryUserInfo.cfm <cf_querysim> AllUsers userID,firstName,lastName,newsletters 100|Stan|Cox|19 200|Haywood U.|Buzzoff|5 300|Marge|Inoferror|11 </cf_querysim> <cfquery dbtype="query" name="UserInfo"> SELECT * FROM AllUsers WHERE userID = #attributes.userID# </cfquery>
Write fuses: dspUserInfoForm.cfm <cf_<h2>User Profile</h2> <cfoutput> <form action="#self#?fuseaction=#xfa.submitForm#" method="post"> <table border="0" align="left" width="500"> <tr> <td align="right">First name: </td> <td><input type="Text" name="firstName" value="#UserInfo.firstName#" /></td> </tr> <tr> <td align="right">Last name: </td> <td><input type="Text" name="lastName" value="#UserInfo.lastName#" /></td> </tr>
Write fuses: dspUserInfoForm.cfm <tr> <td align="right">Newsletters: </td> <td> <cfloop query="Newsletters"> <input type="Checkbox" name="newsletters" value="#Newsletters.newsletterID#" <cfif BitAnd(Newsletters.newsletterID, UserInfo.newsletters)> checked</cfif>> #newsletterName#<br> </cfloop> </td> </tr> <tr> <td colspan="2" align="center"> <input type="Submit" value=" ok " /> </td> </tr>
Write fuses: dspUserInfoForm.cfm </table> <input type="Hidden" name="userID" value="#UserInfo.userID#" /> </form> </cfoutput>
Write fuses: qryUserInfoEmpty.cfm <cf_querysim> UserInfo userID,firstName,lastName,newsletters ""|""|""|0 </cf_querysim>
Write test harnesses!!! • Make sure that all your fuses fulfill their contract • For this, you will need to use the Fusedocs
Define how/what fuseactions the Users circuit will handle: circuit.xml <circuit access="public"> <fuseaction name="list"> <xfa name="editUser" value="Users.edit" /> <xfa name="newUser" value="Users.new" /> <include template="qryAllUsers.cfm" /> <include template="dspUserList.cfm" /> </fuseaction> <fuseaction name="edit"> <xfa name="submitForm" value="Users.doEdit" /> <xfa name="home" value="Users.list" /> <include template="qryNewsletters.cfm" /> <include template="qryUserInfo.cfm" /> <include template="dspUserInfoForm.cfm" /> </fuseaction>
Define how/what fuseactions the Users circuit will handle: circuit.xml <fuseaction name="new"> <xfa name="submitForm" value="Users.doNew" /> <xfa name="home" value="Users.list" /> <set name="dsn" value="OurApp" /> <do action="query.getNewsletters" /> <include template="dspUserInfoForm.cfm" /> </fuseaction> <fuseaction name="doEdit"> </fuseaction> <fuseaction name="doNew"> </fuseaction> </circuit>
Define the configuration for the Fusebox application: fusebox.xml <?xml version="1.0" encoding="UTF-8"?> <fusebox> <circuits> <circuit alias="Users" path="circuits/Users/" parent=""/> </circuits>
Define the configuration for the Fusebox application: fusebox.xml <parameters> <parameter name="fuseactionVariable" value="fuseaction" /> <parameter name="defaultFuseaction" value="Users.list" /> <parameter name="precedenceFormOrUrl" value="form"/> <parameter name="reparse" value="true" /> <parameter name="execute" value="true" /> <parameter name="mode" value="development"/> <parameter name="parseWithComments" value="true" /> (continued)
Define the configuration for the Fusebox application: fusebox.xml <parameter name="scriptFileDelimiter" value="cfm"/> <parameter name="maskedFileDelimiters" value="htm,cfm,cfml,php,php4,asp,aspx"/> </parameters> <globalfuseactions> <preprocess> </preprocess> <postprocess> </postprocess> </globalfuseactions> (continued)
Define the configuration for the Fusebox application: fusebox.xml <plugins> <phase name="preProcess"> </phase> <phase name="preFuseaction"> </phase> <phase name="postFuseaction"> </phase> <phase name="fuseactionException"> </phase> <phase name="postProcess"> </phase> <phase name="processError"> </phase> </plugins> </fusebox>
The Fusebox grammar • include • <include template="dspProducts" /> • set • <set name="dsn" value="FruitProducts" /> • xfa • <xfa name="success" value="home.main" /> • do • <do action="home.listProducts" /> • relocate • <relocate url="http://techspedition.com" /> • if • loop
Good Stuff in Fusebox 4 • Language/version-neutral syntax • Extensibility through plugins • Improved performance • No gut-wrenching changes • Can execute multiple fuseactions in same HTTP request (reduces <cfmodule> calls) • Very flexible content components • Less need to understand the Fusebox API
For more info… • www.fusebox.org site and forums • Discovering Fusebox 4 book at techspedition.com • Classes (halhelms.com) • FastTrack to Fusebox 4 • Fusebox Mastery class • Fusebox Lifecycle Process (FLiP) • Articles in "ColdFusion Developer's Journal"