Skip to main content
Ben Nadel at CFUNITED 2010 (Landsdown, VA) with: Virginia Klebau
Ben Nadel at CFUNITED 2010 (Landsdown, VA) with: Virginia Klebau

CFModule Template Attribute Error Message In Adobe ColdFusion

By
Published in

Yesterday, in an exploration of ColdFusion custom tags in Adobe ColdFusion, I ran into an issue with the template attribute of the cfmodule tag. Unlike other attributes, the template attribute cannot be passed into the cfmodule tag as part of the attributeCollection mechanics. This behavior is documented on Adobe site:

Note: This attribute functions differently from the attributeCollection attribute that is supported by most other tags. You must specify the name and template attributes as direct cfmodule tag attributes, not in the attributeCollection structure.

I didn't know about this (or had forgotten); and wanted to write this blog post as a note to self, especially since the error message I was receiving was cryptic and didn't point me to the underlying cause of the error.

To demonstrate, I have a noop.cfm tag that does nothing. And I'm trying to invoke it via the attributeCollection:

<cfscript>

	attrs = {
		template: "./noop.cfm"
	};

	// ADOBE COLDFUSION (documented): Unlike other tags, you MUST pass name/template
	// attributes as explicit attributes to the CFModule tag. They cannot be collected as
	// passed as a group. This does not apply to Lucee CFML.
	cfmodule( attributeCollection = attrs ) {
		writeOutput( "Tag body here...." );
	}

</cfscript>

If I run this CFML code in Adobe ColdFusion, I get the following error:

Type: java.lang.NullPointerException

Message: Cannot invoke "coldfusion.runtime.NeoPageContext.pushBody()" because "this.tagPageContext" is null.

Stacktrace:
java.lang.NullPointerException: Cannot invoke "coldfusion.runtime.NeoPageContext.pushBody()" because "this.tagPageContext" is null at coldfusion.tagext.lang.ModuleTag.doAfterBody(ModuleTag.java:391)

As you can see, the error message provides no meaningful insight about the template attribute. But now, when I Google it next time, I'm hoping that this post will come up.

To fix this, all I have to do is explicitly provide the template attribute even if I'm going to use the attributeCollection for subsequent attributes:

<cfscript>

	attrs = {
		hello: "world",
		foo: "bar"
	};

	// Always provide `template` explicitly!
	cfmodule(
		template = "./noop.cfm",
		attributeCollection = attrs
		) {
		writeOutput( "Tag body here...." );
	}

</cfscript>

As a final note, Lucee CFML doesn't have an issue with this.

Want to use code from this post? Check out the license.

Reader Comments

Post A Comment — I'd Love To Hear From You!

Post a Comment

I believe in love. I believe in compassion. I believe in human rights. I believe that we can afford to give more of these gifts to the world around us because it costs us nothing to be decent and kind and understanding. And, I want you to know that when you land on this site, you are accepted for who you are, no matter how you identify, what truths you live, or whatever kind of goofy shit makes you feel alive! Rock on with your bad self!
Ben Nadel
Managed ColdFusion hosting services provided by:
xByte Cloud Logo