is it possible to use buildURL() in a custom tag for view?

288 views
Skip to first unread message

Henry Ho

unread,
Jul 27, 2010, 1:56:48 PM7/27/10
to framework-one
This is my first time writing custom tag, so maybe I missed something.
I tried calling caller.buildURL(), but it doesn't work and throws an
exception about something in variables scope not defined.

Thanks,
Henry

Sean Corfield

unread,
Jul 27, 2010, 4:40:22 PM7/27/10
to framew...@googlegroups.com
Views are executed in the context of framework.cfc (i.e., your
Application.cfc) so all methods are available in those - so I would
have expected caller.buildURL() to work. Can you provide more detail?

Henry Ho

unread,
Jul 28, 2010, 1:27:36 AM7/28/10
to framework-one
I called <cf_li>, and li.cfm is simply
<cfoutput>#caller.buildURL("123")#</cfoutput>

Then this exception is thrown:

Element FRAMEWORK.BASEURL is undefined in VARIABLES.

The error occurred in C:\ColdFusion9Frameworks\org\corfield
\framework.cfc: line 36
Called from C:\ColdFusion9\wwwroot\layouts\li.cfm: line 1
Called from C:\ColdFusion9\wwwroot\layouts\default.cfm: line 23
Called from C:\ColdFusion9Frameworks\org\corfield\framework.cfc: line
1411
Called from C:\ColdFusion9Frameworks\org\corfield\framework.cfc: line
518

34 : <cffunction name="buildURL" access="public" output="false">
35 : <cfargument name="action" type="string" />
36 : <cfargument name="path" type="string"
default="#variables.framework.baseURL#" />
37 : <cfargument name="queryString" type="string" default="" />
38 :

Thanks,
Henry

Sean Corfield

unread,
Jul 28, 2010, 2:30:16 AM7/28/10
to framew...@googlegroups.com
Ah, yes, now I remember (from the ColdBox app I've been working on)...
CFML kinda gets the scopes wrong. If you add:

variables.baseurl = caller.baseurl;

in your custom tag (and the same for any similar errors) you should be
able to get it to work.

Sean

Henry Ho

unread,
Jul 28, 2010, 3:41:06 AM7/28/10
to framew...@googlegroups.com
Sean, it doesn't work.


<cfset variables.baseurl = caller.baseurl> // throws exception:
Element BASEURL is undefined in CALLER.
<cfoutput>#buildURL("abc")#</cfoutput>


<!--- Then I cfdump caller and located baseurl in framework struct,
so I tried this --->

<cfset variables.framework = caller.framework>
<cfoutput>#buildURL("abc")#</cfoutput>

Variable GETFULLYQUALIFIEDACTION is undefined.

The error occurred in
C:\ColdFusion9Frameworks\org\corfield\framework.cfc: line 83
Called from C:\ColdFusion9\wwwroot\layouts\li.cfm: line 2
Called from C:\ColdFusion9\wwwroot\layouts\default.cfm: line 17


Called from C:\ColdFusion9Frameworks\org\corfield\framework.cfc: line 1411
Called from C:\ColdFusion9Frameworks\org\corfield\framework.cfc: line 518

81 : <cfset basePath = arguments.path & initialDelim & replace(
getFullyQualifiedAction( arguments.action ), '.', '/' ) />
82 : <cfelse>
83 : <cfset basePath = arguments.path & initialDelim &
variables.framework.action & equalDelim &
getFullyQualifiedAction(arguments.action) />
84 : </cfif>


Thanks,
Henry

> --
> FW/1 on RIAForge: http://fw1.riaforge.org/
>
> FW/1 on github: http://github.com/seancorfield/fw1
>
> FW/1 on Google Groups: http://groups.google.com/group/framework-one

Brian Meloche

unread,
Jul 28, 2010, 6:40:56 PM7/28/10
to framew...@googlegroups.com
I've run into this, as LightFront does this, too. Try:

<cfset structAppend(variables, caller)>

This is a little heavy handed, so you may want to scale back an entire
copying of the variables scope once you figure out what you need. :-)

The other possibility is to pass in what you need via attributes.

Henry Ho

unread,
Jul 28, 2010, 6:46:58 PM7/28/10
to framew...@googlegroups.com
Thanks, I wonder if it is cleaner if the view can access variables.fw
just like in controller.

composition over inheritance, and no scope issue?

Just need to call fw.buildURL() instead of buildURL().. but how?


Henry

Sean Corfield

unread,
Jul 28, 2010, 11:59:15 PM7/28/10
to framew...@googlegroups.com
On Wed, Jul 28, 2010 at 6:46 PM, Henry Ho <henry...@gmail.com> wrote:
> Thanks, I wonder if it is cleaner if the view can access variables.fw
> just like in controller.

Well, the view *can* access variables.buildURL() or this.buildURL() -
the "fw" is THIS scope so what you might try is this on your custom
tag:

<cf_mytag fw=this> ... </cf_mytag>

and then attributes.fw.buildURL() might work inside the custom tag.
--
Sean A Corfield -- (904) 302-SEAN
Railo Technologies, Inc. -- http://getrailo.com/
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

Adam Tuttle

unread,
Dec 23, 2010, 8:54:53 AM12/23/10
to framew...@googlegroups.com

Sean Corfield

unread,
Dec 23, 2010, 1:06:30 PM12/23/10
to framew...@googlegroups.com
On Thu, Dec 23, 2010 at 5:54 AM, Adam Tuttle <ad...@fusiongrokker.com> wrote:
> Here's what I think is a better solution:
> http://fusiongrokker.com/post/using-the-fw-1-buildurl-helper-method-inside-custom-tags

Ooh, that is slick! And I should have thought of it since I'm using a
similar technique with ColdBox (where you have to alias a several
variables to make this sort of stuff work). Can't remember who
suggested it for ColdBox... probably Luis (so, thank you Luis, if it
was you!).

Reply all
Reply to author
Forward
0 new messages