Hi Folks,

I have a CFC that writes HTML code including some anchor tags. I don't
want the CFC to know how to write the links. That decision really belongs 
to the layer that calls it. I don't want the CFC to be coupled to:

1. The Fusebox framework 
2. The name and location of the controller page (/index.cfm)
3. The fact that there is a controller page at all
4. The fact that I'm using "&" to delimit parameters (not search-engine-safe)
5. The names of the fuseactions that relate to each exit point
6. The names of the URL parameters 

Using a variable called "self" instead of hard-coding "index.cfm"
takes care of #2. Hal's XFAs take care of #5. These are both old ideas
from circa CF 3.1. I'm sure that we can fully abstract the way links
are written using CFCs. I'd be surprised if a lot of people aren't
already doing that. I just don't know where to look.

This morning in the shower I brainstormed a "ExitPoint" component that
would keep track of a set of exit points and how to write the links
for those exit points.


First initialize the exitPoints object and tell it to write links Fusebox-style.
exitPoints = createObject("component", "ExitPoints");
writer = createObject("Component", "FuseBoxExitPointWriter");
writer.init("/index.cfm", "fuseaction")
exitPoints.setWriter(writer):

Then define the exit points.
exitPoints.add("createPerson", "ppl.newPersonForm");
exitPoints.add("selectPerson", "ppl.editPersonForm", "personID");
exitPoints.add("removePerson", "groups.dropPerson", "personID", "groupID");

The first argument of the add method is the name of the exit point.
The second argument is the name of the action. (In this case it's a fuseaction, 
but it could be an event, page name, etc.) The rest of the arguments are 
paramters that must be passed out of the exit point.

Here's how the exit points would be used:

<a href="#exitPoints.write('createPerson')#">Create Person</a><br>
<cfloop query="people">
  <a href="#exitPoints.write('selectPerson', people.id)#">#people.name#</a>
  <a href="#exitPoints.write('removePerson', people.id, groupID)#">[remove]</a>
  <br>
</cfloop>


Here's what the resulting HTML would look like:

<a href="/index.cfm?fuseaction=ppl.newPersonForm">Create Person</a><br>
<a href="/index.cfm?fuseaction=ppl.editPersonForm&personID=1">Bob</a>
<a href="/index.cfm?fuseaction=groups.dropPerson&personID=1&groupID=4">[remove]</a>
<br>
<a href="/index.cfm?fuseaction=ppl.editPersonForm&personID=2">Larry</a>
<a href="/index.cfm?fuseaction=groups.dropPerson&personID=2&groupID=4">[remove]</a>
<br>

Again, I won't be surprised if something like this is already a common 
practice. I would appreciate if someone would point me in the right direction.

-- 
Patrick McElhaney
704.560.9117
http://pmcelhaney.blogspot.com
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' 
in the message of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]

Reply via email to