>> GreenByte.info By Nick Tong (quiksilv) | Supported by: TalkWebSolutions.co.uk

Fusebox 101: What's XFA all about?

I've just been chatting with someone about the XFA in verb for fusebox and I thought I would post my thoughts.

XFA stands for eXit FuseAction - this is where you store variables to be used in your web pages. The question here is, why use it?

Well imagine this, you have a login form that is used on your website. When a user goes to certain areas, you check to see if the user is logged in. If they are, then they will continue as normal, on the other hand they will need to login.

Being a great coder you don't want to have lots of forms all over the place, so you include one login form. This form then performs different actions depending on the what you need it to do.

Instead of having cfif's at the top of the form tell the form where it should go, you simple use the XFA verb that fusebox provides to store you variables. For example:

<fuseaction name="userLogin">
<xfa name="login" value="user.actLogin" />
< include template="frmLogin" contentvariable="layout.bodyContent" />
</fuseaction>

<fuseaction name="adminLogin">
<xfa name="login" value="admin.actLogin" />
< include template="frmLogin" contentvariable="layout.bodyContent" />
</fuseaction>

Both these fuseactions called (userLogin, adminLogin) include the same form page but have different XFAs. Your login form could look like:

<form id="login" method="post" action="<cfoutput>#request.myself##xfa.login#</cfoutput>">
<input id="userName" ... />
<input id="password" ... />
<input id="submit" ... />
</form>

Using XFAs allows code/pages to be reused in lots of places like: forms, links, relocations etc.

If you are using fusebox 3 you would set your XFA in the FBX_Switch.cfm page like

For XFAs in fusebox 3, Hal has a great post here

PS: this is my 250th blog post - w00t!


 

Related Blog Entries

Comments
Russ Michaels's Gravatar Surely this results in you needing an XFA on every page? Ass apposed to the good old fashioned method of check if user is logged in on the index page, or in the application.cfm/cfc, if not, redirect to login page.
# Posted By Russ Michaels | 03/09/07 23:39 | Report abusive comment
Nick Tong's Gravatar Hi Russ,
The logic of this post isn't really about how to handle your logins but how to use XFAs. I'm also not suggesting where one checks to see if a user is logged in.

You are right in the fact that every time you call in the login page you will need to set the XFA, but this is small cost for a reusable page.
# Posted By Nick Tong | 04/09/07 07:52 | Report abusive comment
Brian Kotek's Gravatar It can take a little while to wrap your head around the power of XFAs (or eXit Events (XEs) as I call them in Mach-II/Model-Glue). The point is that you remove decisions about the page flow from the View templates and instead make them where they belong, in the Controller. Not only is this just a better way to handle the page flow, but it greatly increases the reusability of your view templates because they are no longer tied to specific request handlers.
# Posted By Brian Kotek | 04/09/07 15:25 | Report abusive comment
Sean Corfield's Gravatar At first I thought XFAs were an unnecessary level of abstraction but once I started using them "religiously", I found it very, very useful to decouple the actual flow from the views and I use them for *every* link out of a page and every form post. This allows the flow of control to be specified entirely in the controller (where it should be) and it makes it easy to "rewire" pages and links. I took the practice from Fusebox across to Mach-II back in early 2004:

http://livedocs.adobe.com/wtg/public/machiidevguid...

And from there I took it into Model-Glue as well in early 2005:

http://corfield.org/entry/ModelGlue_Sample_Applica...

It really is a powerful abstraction!
# Posted By Sean Corfield | 04/09/07 21:24 | Report abusive comment
Peter Bell's Gravatar I do something similar with an "action" variable. For a more page centric approach (most of my apps are at heart content management systems) I also have a #Page.get("URL")# property, so any view can return to the appropriate URL (maybe /about-us/history.html or /products/luggage/briggs-riley.html). Both are extremely useful for reuse of views.
# Posted By Peter Bell | 05/09/07 14:36 | Report abusive comment
BlogCFC was created by Raymond Camden. This blog is running version 5.5.1.