Skip to main content
December 2, 2009
Answered

cfparam only works when type="any" and default=""

  • December 2, 2009
  • 2 replies
  • 1437 views

I am trying to add cfparam to a custom tag to validate the data. However, it always errors on valid data.

This works:

  <!--- this is page test2.cfm --->
    <cfmodule template = "components/test2component.cfm" columns=14 >  

<!--- This is components/test2component.cfm --->


<cfparam name="columns" type="any" default="">

<cfoutput> #attributes.columns# </cfoutput>
  <a href="#goTop" title="Go to top of page">Top</a>

<!--- the output is --->

14 
          <a href="#goTop" title="Go to top of page">Top</a>

-----------------------------------------------------------------------------------------

But when I change the component to:

<cfparam name="columns" type="integer" default="">

<cfoutput> #attributes.columns# </cfoutput>
  <a href="#goTop" title="Go to top of page">Top</a>

I get this:

Invalid parameter type.

The value specified, '', must be a valid integer.

-----------------------------------------------------

When I change the component to:

<cfparam name="columns" type="integer">

<cfoutput> #attributes.columns# </cfoutput>
  <a href="#goTop" title="Go to top of page">Top</a>

I get this:

The required parameter columns was not provided.

This page uses the cfparam tag to declare the parameter columns as required for this template. The parameter is not available. Ensure that you have passed or initialized the parameter correctly. To set a default value for the parameter, use the default attribute of the cfparam tag.   The error occurred in D:\Inetpub\wwwroot\endpoints\components\test2component.cfm: line 19

Any suggestions?

This topic has been closed for replies.
Correct answer ilssac

I suspect this is a scope issue.

Data provided to a custom tag, such as you show in this line.

<cfmodule template = "components/test2component.cfm" columns=14 >

Are accessed from the attributes scope.

Your <cfparam....> variable as shown in this line:
<cfparam name="columns" type="integer">

Is not specifying a scope for the columns variable so ColdFusion is guessing.

Try this line.

<cfparam name="attributes.columns" type="integer">

2 replies

ilssac
ilssacCorrect answer
Inspiring
December 2, 2009

I suspect this is a scope issue.

Data provided to a custom tag, such as you show in this line.

<cfmodule template = "components/test2component.cfm" columns=14 >

Are accessed from the attributes scope.

Your <cfparam....> variable as shown in this line:
<cfparam name="columns" type="integer">

Is not specifying a scope for the columns variable so ColdFusion is guessing.

Try this line.

<cfparam name="attributes.columns" type="integer">
December 2, 2009

Thanks. I appreciate the response. It seems like thinking about it enough to write it down worked.

ilssac
Inspiring
December 2, 2009

henryhelgen wrote:

Thanks. I appreciate the response. It seems like thinking about it enough to write it down worked.

That has happend to me many times.

December 2, 2009

Ok, I solved it. The cfparam needs the attributes scope.

<cfparam name="attributes.columns" type="integer">

<cfoutput> #attributes.columns# </cfoutput>
  <a href="#goTop" title="Go to top of page">Top</a>

ilssac
Inspiring
December 2, 2009

Well just go ahead and solve it yourself before I can type up a nice response!