Closed CFModule makes it execute twice

304 views
Skip to first unread message

Stefan

unread,
Nov 4, 2009, 11:34:59 PM11/4/09
to Railo
I know I read about this with customtags in cf many years ago and I
have never put end tags like this before:
<cfmodule template="/templates/template.cfm" data="data" />
But now I had to use an editor that complained about non closed tags
all the time, so I closed it. Everything was doubled. I removed the /
and all was fine. Is that expected behavior or is it a configuration
issue?
It does not make sense to me. Is there any other tags that behaves
this way?

Thanks
Stefan

Barney Boisvert

unread,
Nov 4, 2009, 11:43:36 PM11/4/09
to ra...@googlegroups.com
Any custom tag, regardless of how it's invoked, will behave like this.
This has been the way it's worked since the earliest days of custom
tags on Adobe CF. A custom tag is executed once for the open tag and
once for the close tag (if present), including a self-close as you
illustrated. Within the tag, you can differentiate between the two
scenarios by using thisTag.executionMode. In general, any tag
designed to work without a close tag can have this snippet added to
the top to "fix" it's behaviour when self-closed:

<cfif thisTag.executionMode EQ "end">
<cfexit method="exittag" />
</cfif>

Just for reference, custom tag invocation can take any of these forms:

<cfmodule name="myTag" />
<cf_myTag />
<cfmodule template="myTag.cfm" />
<cfimport prefix="t" taglib="." /><t:myTag />

All four forms are equivalent if 'myTag.cfm' is in the same directory.
If it is missing, the last two forms will immediately fail, while the
first two will also scan registered custom tag paths looking for
'myTag.cfm'.

Your example is a specialization of the third form, where the explict
tag path is computed based on a mapping, rather than the current
template path. Regardless, it's a fixed path to check (last two
forms), not a name to search for (first two forms).

cheers,
barneyb


--
Barney Boisvert
bboi...@gmail.com
http://www.barneyb.com/

Martijn van der Woud

unread,
Nov 5, 2009, 3:13:19 AM11/5/09
to Railo
Thanks Barney for refreshing my memory! My knowledge of custom tags is
getting rusty so this helps! :)
Martijn
> On Wed, Nov 4, 2009 at 8:34 PM, Stefan <stefan.vesterl...@googlemail.com> wrote:
>
> > I know I read about this with customtags in cf many years ago and I
> > have never put end tags like this before:
> > <cfmodule template="/templates/template.cfm" data="data" />
> > But now I had to use an editor that complained about non closed tags
> > all the time, so I closed it. Everything was doubled. I removed the /
> > and all was fine. Is that expected behavior or is it a configuration
> > issue?
> > It does not make sense to me. Is there any other tags that behaves
> > this way?
>
> > Thanks
> > Stefan
>
> --
> Barney Boisvert
> bboisv...@gmail.comhttp://www.barneyb.com/

Stefan

unread,
Nov 5, 2009, 11:16:33 AM11/5/09
to Railo
Thanks Barney. Yes, I know the principles, I just assumed that the
mechanism would recognize that I closed the tag rather than put an end
tag. I can see no reason why one would either expect or need that
behavior. But maybe it is not a big deal :)
> On Wed, Nov 4, 2009 at 8:34 PM, Stefan <stefan.vesterl...@googlemail.com> wrote:
>
> > I know I read about this with customtags in cf many years ago and I
> > have never put end tags like this before:
> > <cfmodule template="/templates/template.cfm" data="data" />
> > But now I had to use an editor that complained about non closed tags
> > all the time, so I closed it. Everything was doubled. I removed the /
> > and all was fine. Is that expected behavior or is it a configuration
> > issue?
> > It does not make sense to me. Is there any other tags that behaves
> > this way?
>
> > Thanks
> > Stefan
>
> --
> Barney Boisvert
> bboisv...@gmail.comhttp://www.barneyb.com/

Barney Boisvert

unread,
Nov 5, 2009, 11:57:57 AM11/5/09
to ra...@googlegroups.com
Closing a tag IS an end tag, it's just a syntactic shortcut for when
the tag has no body. That's not CFML specific, it's the same for
pretty much any markup language, and certainly for any XML
application. To put that another way, I don't know of any situation
in any language where these two are semantically different:

<tag />
<tag></tag>

A lot of custom tags do their processing in the end tag, so they can
check the existence of generated body content and react to it. For
those tags, you MUST have an end tag, regardless of whether you
actually have generated content. Since that's such a common need, the
self-close was created as a special case to reduce verbosity without
affecting semantics.

cheers,
barneyb

Todd Rafferty

unread,
Nov 5, 2009, 12:13:59 PM11/5/09
to ra...@googlegroups.com
Why is why I hate it when people do: <cfreturn data />. There's no <cfreturn>data</cfreturn> equivalent. Not all tags need to be closed and imho, shouldn't be closed, but whatever. :)

~Todd Rafferty ** Volunteer Railo Open Source Community Manager ** http://getrailo.org/

Paul Kukiel

unread,
Nov 5, 2009, 12:17:08 PM11/5/09
to ra...@googlegroups.com

LOL don’t start this again J

 

http://blog.kukiel.net/2009/09/do-you-close-your-coldfusion-tags.html

 

Most commented post I made.

 

I how ever agree with Todd’s last comment   

 

 “whatever” J

 

Paul.

Todd Rafferty

unread,
Nov 5, 2009, 12:20:27 PM11/5/09
to ra...@googlegroups.com
Hey, you know me, I'm always up for a good "Whatever."


~Todd Rafferty ** Volunteer Railo Open Source Community Manager ** http://getrailo.org/

On Thu, Nov 5, 2009 at 12:17 PM, Paul Kukiel <kuk...@gmail.com> wrote:

LOL don’t start this again

 Most commented post I made.

 I how ever agree with Todd’s last comment   

  “whatever” 

Paul.

Barney Boisvert

unread,
Nov 5, 2009, 12:30:50 PM11/5/09
to ra...@googlegroups.com
The equivalent of <cfreturn data /> would be <cfreturn
data></cfreturn>. <cfreturn>data</cfreturn> is a very different
construct (data as a child element, rather than as a tag "attribute").

I happen to like the closing tags because I can see if my markup is
balanced without reading the tag names. But I'm with you, "whatever".
A personal stylistic decision, outside custom tags that aren't
written defensively.

cheers,
barneyb

On Thu, Nov 5, 2009 at 9:13 AM, Todd Rafferty <to...@getrailo.org> wrote:
> Why is why I hate it when people do: <cfreturn data />. There's no
> <cfreturn>data</cfreturn> equivalent. Not all tags need to be closed and
> imho, shouldn't be closed, but whatever. :)
>
> ~Todd Rafferty ** Volunteer Railo Open Source Community Manager **
> http://getrailo.org/
>

--

Todd Rafferty

unread,
Nov 5, 2009, 12:32:52 PM11/5/09
to ra...@googlegroups.com
Thanks, brain fart on my part.


~Todd Rafferty ** Volunteer Railo Open Source Community Manager ** http://getrailo.org/

Stefan

unread,
Nov 6, 2009, 10:00:40 AM11/6/09
to Railo
I do <br />
Problem is that when doing cfml, you often use ?ml editors. It does
not really matter what the tags means, they just see that some of them
are not closed and freaks out.
I never write <cfset a = 3 /> though, but if I did I would not expect
an error. Just as I did not expect <cfmodule /> to be executed twice.


On Nov 5, 6:13 pm, Todd Rafferty <t...@getrailo.org> wrote:
> Why is why I hate it when people do: <cfreturn data />. There's no
> <cfreturn>data</cfreturn> equivalent. Not all tags need to be closed and
> imho, shouldn't be closed, but whatever. :)
>
> ~Todd Rafferty ** Volunteer Railo Open Source Community Manager **http://getrailo.org/

Todd Rafferty

unread,
Nov 6, 2009, 10:03:16 AM11/6/09
to ra...@googlegroups.com
<br /> is xhtml tho and part of a set of rules to follow to be xhtml compliant. <cfset a = 4 /> is not xhtml, nor is it necessary. It just appears to be a developer preference.


~Todd Rafferty ** Volunteer Railo Open Source Community Manager ** http://getrailo.org/

Michael Offner-Streit

unread,
Nov 6, 2009, 10:41:58 AM11/6/09
to ra...@googlegroups.com
in cfml are 3 different types of tags.

tags with no end tags like cfset, cfparam, cfreturn , cfargument, cfdump ...
this tags can not have a end tag, end tag is ignored (shorthand end tag) or a exception is throwed (ent tag)

tags with optional end tags like cfcache, cfchart, cfcontent, cfdiv, cfmodule ...
this tag can have a end tag but the end tag is not required, shorthand end tag and regular end tag is handled the same way.

tags where end tag is required like cfcase,cfswitch,cfcatch,cfcomponent,cffinally,cfform,cffunction,cfmail
this tag must have a end tag, shorthand end tag and regular end tag is handled the same way.

xml and xhtml only knows the last group.

/micha




Stefan schrieb:

Stefan

unread,
Nov 6, 2009, 11:06:00 AM11/6/09
to Railo
I know that, but what I am trying to say is that developers
preferences often depends on the developers tools. And when the tool
is complaining about your cfml syntax, sometimes you aim to satisfy
the tool rather than your personal preferences. Unfortunately, not
many tools understands cfml.

On Nov 6, 4:03 pm, Todd Rafferty <t...@getrailo.org> wrote:
> <br /> is xhtml tho and part of a set of rules to follow to be xhtml
> compliant. <cfset a = 4 /> is not xhtml, nor is it necessary. It just
> appears to be a developer preference.
>
> ~Todd Rafferty ** Volunteer Railo Open Source Community Manager **http://getrailo.org/

Todd Rafferty

unread,
Nov 6, 2009, 11:09:19 AM11/6/09
to ra...@googlegroups.com
I use:
* Dreamweaver CS3 & CS4
* ColdFusion Builder (Beta 1 / Beta 2)

I don't recall either one of these complaining to me about this. What tool are you using?

~Todd Rafferty ** Volunteer Railo Open Source Community Manager ** http://getrailo.org/

Peter Boughton

unread,
Nov 6, 2009, 11:12:44 AM11/6/09
to ra...@googlegroups.com
Stefan, is there a specific feature/functionality which requires that
you use tools that don't understand CFML?

Or - to put it another way - how about making feature request(s) for
CFEclipse and CFBuilder, detailing the functionalities you want them
to have? :)

Gerald Guido

unread,
Nov 6, 2009, 11:21:37 AM11/6/09
to ra...@googlegroups.com
>>you often use ?ml editors. It does
not really matter what the tags means, they just see that some of them
are not closed and freaks out.

If that is the case just put the code inside this cfif statement and it will only execute once.

<cfif thisTag.executionMode is "start">
 Put your code here
</cfif>

There. Problem solved.

G!

On Fri, Nov 6, 2009 at 10:00 AM, Stefan <stefan.v...@googlemail.com> wrote:



--
Gerald Guido
http://www.myinternetisbroken.com

"Wait. We can't stop here. This is bat country."
-- HST

Stefan

unread,
Nov 6, 2009, 11:24:53 AM11/6/09
to Railo
I normally use Eclipse and with CFEclipse there is no problem. But
then I jumped to Mac a while ago and have been evaluating new tools. I
love Eclipse in many ways, but it can also be extremely annoying at
times, so I was just looking around a bit. I am not really
complaining, and for me it is not a real problem. I have gone back to
Eclipse and is happy with it. On the other hand, it is very difficult
to find a code cleaning/reformatting tool that works with cfml because
of the open tags. That is something that sometimes would come in
handy. All in all, not a huge problem, but if we could code according
to xml syntax, a new range of tools would be available for us. Or
whatever :)

On Nov 6, 5:09 pm, Todd Rafferty <t...@getrailo.org> wrote:
> I use:
> * Dreamweaver CS3 & CS4
> * ColdFusion Builder (Beta 1 / Beta 2)
>
> I don't recall either one of these complaining to me about this. What tool
> are you using?
>
> ~Todd Rafferty ** Volunteer Railo Open Source Community Manager **http://getrailo.org/

Peter Boughton

unread,
Nov 6, 2009, 11:39:42 AM11/6/09
to ra...@googlegroups.com
> On the other hand, it is very difficult
> to find a code cleaning/reformatting tool that works with cfml because
> of the open tags. That is something that sometimes would come in
> handy.

Working on that. :)

It's going to take a while - need to get a suitable parser created
first - but being able to define a set of formatting rules and applied
either on-demand and/or at key points is definitely one of the goals.

Stefan

unread,
Nov 6, 2009, 12:14:16 PM11/6/09
to Railo
Sounds great.
Will be my valuable friend until we have XCFML :)

Peter Boughton

unread,
Nov 6, 2009, 12:25:07 PM11/6/09
to ra...@googlegroups.com
You don't *really* want XCFML.


I mean, compare this simple conditional:

<cfif This EQ That>
a
<cfelseif This GT That>
b
<cfelse>
c
</cfif>


Versus:

<cfif condition="This EQ That">
<cftrue>
a
</cftrue>
<cffalse>
<cfif condition="This GT That">
<cftrue>
b
</cftrue>
<cffalse>
c
</cffalse>
</cfif>
</cffalse>
</cfif>


Eugh. :&

Reply all
Reply to author
Forward
0 new messages