the singularity of being and nothingness
Gotcha with Dynamic Component Method Invocation
In an app I’m currently working on, I came across the need to be able to invoke methods from a particular component dynamically. On the surface, this is pretty simple:
myComp = createobject("component","com.utils").init();
dyn = myComp[methodvariable];
dyn();
While this technically *works*, there is one huge gotcha: there does not appear to be any persistence of the initialized component from init() to dyn(). That is, if the init method, say, sets up datasource names and other component properties, these will no longer be available in the invocation of dyn(). Not a big deal, I guess, if you don’t have need of the init function…but a killer if you do.
Fortunately, it’s easy enough to work around this. After you’ve instantiated the component, just use to call the dynamic method:
<cfinvoke component="#myComp#" method="#methodvariable#" /> (cfinvoke is still tag-bound...sorry! :))
Anyway, easy enough, but something a person can easily spend FAR too much time trying to work out. Uggh.
Share this:
|
Share this post!
| Print article | This entry was posted by existdissolve on September 30, 2010 at 2:59 am, and is filed under ColdFusion. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
No comments yet.
No trackbacks yet.
Multi-CFML Engine Environment on Apache
about 10 years ago - No comments
For local development, I typically deal with ColdFusion 10 and Railo 4. Recently, however, the pain of switching back and forth (copying files and what not) has surpassed the threshold of feasibility. Plus, I would *really* like to be able to easily test ColdFusion 9 and ColdFusion 11 as well (specifically for compatibility with ContentBox).…
Share this:
ColdFusion ORM - Collection…was not processed by flush()
about 12 years ago - 2 comments
This is more for my own memory, but perhaps it will be useful to others 🙂 Let’s say I have the following entities: User.cfc component persistent=”true” entityname=”User” table=”User” { property name=”UserID” fieldtype=”id”; property name=”Name”; property name=”Age”; property name=”Group” fieldtype=”many-to-one” cfc=”Group” fkcolumn=”GroupID”; } Group.cfc component persistent=”true” entityname=”Group” table=”Group” { property name=”GroupID” fieldtype=”id”; property name=”Name”; property name=”Activities”…
Share this:
Resolutions and Stuff
about 13 years ago - No comments
I’m not big on resolutions. When I’ve made them in the past, I typically last about 3 whole days before they’re broken and forgotten. Besides, there’s something a bit odd about resolutions anyway. After all, why would we wait until a New Year to do something (lose weight, exercise more, etc.), when it makes a…
Share this:
ColdFusion Gotcha: Switch Statement in CFScript
about 13 years ago - 2 comments
The other day, I was reworking a bit of tag-based code to use my preference of <cfscript> syntax. While doing this, I ran across something like this: <cfswitch expression=”#img.extension#”> <cfcase value=”.gif,.jpg”> Not transparent </cfcase> <cfcase value=”.png”> Transparent </cfcase> </cfswitch> No rocket-science here, just a simple switch statement which just so happens to have a “case”…
Share this:
How I Got Started in ColdFusion
about 13 years ago - 1 comment
This is my contribution to the thread started over at Ray Camden’s site. If you’re a CF developer, be sure to share your thoughts too! Like all good stories, this one begins with bourbon and cheap cigars. Years ago, I was in a poker society with my best friends in the world. We were liturgically…
Share this:
Renaming Files in CFScript
about 13 years ago - 1 comment
I’ve recently taken to writing all of my components in pure cfscript. To me, they look cleaner and are easier to navigate. Plus, I just really like cfscript 🙂 One of the challenges, of course, is that after using tags for so long, it can be sometimes challenging to find equivalent functionality in cfscript. Some…
Share this:
ColdFusion and ORM…Yummy!
about 15 years ago - No comments
The other day, I was flipping through the ColdFusion docs (yeah, super exciting!) and came across the section about ColdFusion's support of ORM. If you're not familiar with it (I wasn't really until a few days ago), ORM stands for "object-relational mapping." While it sounds a bit overly technical, ORM is basically a way to…
Share this:
Turning to the Darkside…of <cfscript>
about 15 years ago - No comments
During a lull at work the other day, I was reading about the extended capabilities that have been added to <cfscript> in ColdFusion 9, like being able to create queries and entire components… Honestly, until recently I've not really used a whole lot of . I'm not really sure why…just not something that interested me…
Share this:
Converting ColdFusion Queries for Ext
about 15 years ago - No comments
At my new job, we use Ext fairly regularly to get some pretty cool AJAXiness up in the mix of things. To familiarize myself with Ext (I’ve not really used it until now), I recently downloaded the newest version and have been playing around with it quite a bit. One of the elements I like…
Share this:
Getting Web Site Screenshots with ColdFusion…and a Little Help
about 15 years ago - 6 comments
For those of you who don't know, I am the owner and occassional operator (!) of CSS {Imagine}, a simple, but relatively well-visited web design gallery. One of the requirements I had for this site when I built it was that I did NOT want to have to do any work of manually grabbing screenshots…