It seems to me the real question is whether redirection is integral to the
operation of a fuse or not. Some fuses have this requirement; others, as
Steve points out, do not. A very simple example of an act file where
redirection is integral would be actProcessLogin.cfm. Here's some
abbreviated code:

actProcessLogin.cfm

<cfif FindUserMatch.recordCount>
  <cflocation url="#self#?fuseaction=#attributes.XFA.successfulLogin#">
<cfelse>
  <cflocation url="#self#?fuseaction=#attributes.XFA.failedLogin#">
</cfif>

Here, we have two distinct "exit points". Hardcoding these is a bad idea if
you want reusability and if you're in a distributed, team environment where
the coder of actProcessLogin does not know where the redirection should be
pointed to (as is always the case when fuses are reused). XFAs let the coder
declare the exit points of the fuse. It is up to the user of the fuse (the
architect) to provide values for these XFAs. This is done in the index.cfm
and is determined at runtime. Here's what the fusebox would look like:

<cfcase value="processLogin">
  <cfset attributes.XFA.successfulLogin = "mainMenu">
  <cfset attributes.XFA.failedLogin = "badLogin">
  <cfinclude template="actProcessLogin.cfm">
</cfcase>

In fact, I define a fuse as a fuse (as opposed to another file that may be
included or called) by the answer to this question: Are exit points integral
to the fuse? If so, I argue that XFAs should be used. Files that do stuff
but don't have explicit exit points need no XFAs, in which case a URL file
would be perfectly appropriate. In that case, the fusebox would look like
this:

<cfcase value="aFuseaction">
  <cfinclude template="aFuseaction.cfm">
  <cfinclude template="url_aURLfile.cfm">
</cfcase>


Hal Helms
== See ColdFusionTraining.com for info on "Best Practices with ColdFusion &
Fusebox" training ==


-----Original Message-----
From: Steve Nelson [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, February 27, 2001 8:06 AM
To: Fusebox
Subject: Re: Why use url_files?


Nat Papovich wrote:
> But this can be easily overcome by checking for the existence of xfa's in
> the fuse before cflocationing, and only providing xfa's to fuses that you
> want to be able to cflocate out of:
> <cfcase value="action2">
>         <cfinclude template="act_page1.cfm">
>         <cfinclude template="act_page2.cfm">
>         <cfset xfa1="blah">
>         <cfset xfa2="blah">
>         <cfinclude template="act_page3.cfm">
> </cfcase>

This is going to quickly get ugly.  Sometimes your act files would need
an xfa depending on the current data. Look at this:

<cfcase value="ViewOrder">
        <cfinclude template="qry_maxorder.cfm">
        <cfinclude template="qry_order.cfm">
        <cfinclude template="url_choosebilling.cfm">
        <cfinclude template="url_chooseshipping.cfm">
        <cfinclude template="act_calculateshipping.cfm">
        <cfset xfa="blah">
        <cfinclude template="dsp_vieworder.cfm">
</cfcase>

Explanation of fuses:

<cfcase value="ViewOrder">
        <!--- a couple queries needed for the act/url/dsp files below --->
        <cfinclude template="qry_maxorder.cfm">
        <cfinclude template="qry_order.cfm">

        <!--- checks to see if the order requires a billing address
                checks to see if a user has already specified billing address
                If this fails it redirects them to /members/addresses/index.cfm--->
        <cfinclude template="url_choosebilling.cfm">

        <!--- checks to see if the order requires a shipping address
                checks to see if a user has already specified shipping address
                If this fails it redirects them to /members/addresses/index.cfm--->
        <cfinclude template="url_chooseshipping.cfm">

        <!--- simply recalculates their shipping depending on the the address
they
                specified after returning from the url_chooseshipping.cfm
redirection--->
        <cfinclude template="act_calculateshipping.cfm">

        <!--- displays the order, the xfa makes sense here--->
        <cfset xfa="blah">
        <cfinclude template="dsp_vieworder.cfm">
</cfcase>

Could this be done with XFAs in act files? Sure, but your not going to
reduce the files because url_choosebilling.cfm/url_chooseshipping.cfm
get reused all over the place, so I would end up with this:

<cfcase value="ViewOrder">
        <cfinclude template="qry_maxorder.cfm">
        <cfinclude template="qry_order.cfm">
        <cfset xfa.billing="...">
        <cfinclude template="act_choosebilling.cfm">
        <cfset xfa.shipping="...">
        <cfinclude template="act_chooseshipping.cfm">

        <!--- uh oh, will this redirect or not??!!!! --->
        <cfinclude template="act_calculateshipping.cfm">

        <cfset xfa="blah">
        <cfinclude template="dsp_vieworder.cfm">
</cfcase>

This is even more complicated code that does the same thing! Except you
get screwed in the act_calculateshipping.cfm because you needed to set
an xfa for act_choosebilling/act_chooseshipping but but not for
act_calculateshipping.cfm.

Sure, you could kludge your way around it, hell it probably wouldn't
even be a problem because you'd name the XFAs different.  But the
reality is that act_calculateshipping.cfm is a calculation script (i
know because i wrote it) which means that it's almost always going to
end up being run in connection with some other script.  There just isn't
a need for ANY redirection in act_calculateshipping.cfm. So why put one
in with an cfif statement around it when it's only going to get called
from a mistake?

I'm just not a big fan of redirection in act files. It makes reuse a
pain in the neck when it doesn't need to be.  URL files are easy to
explain to a newbie, XFAs in act files are not.

Steve Nelson
Online Web Development Training:
http://www.SecretAgents.com/training
(804) 825-6093
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to