The i-Technology Media!
Register | Log in
   
 
.NET  ·  AJAX  ·  CLOUD  ·  ECLIPSE  ·  FLEX  ·  OPEN WEB  ·  iPHONE  ·  JAVA  ·  LINUX  ·  OPEN SOURCE  ·  ORACLE  ·  PBDJ  ·  SEARCH  ·  SILVERLIGHT  ·  SOA  ·  VIRTUALIZATION  ·  WEB 2.0  ·  WIRELESS  ·  XML
Comments
Drool, Britannia? Is the UK Failing the Cloud?
By Roger Strukhoff
Richard Davies wrote: The UK has a good crop of technology pioneers in cloud computing - for example ElasticHosts, FlexiScale, Flexiant, OnApp - and also some strong government initiatives such as G-Cloud. We will have to see whether this kind of technical leadership converts into swift mass-market adoption or not.
Jan. 8, 2012 11:38 AM EST
read more & respond »
Cloud Expo on Google News
Did you read today's front page stories & breaking news?

Cloud Expo & Virtualization 2011 West
Keynotes
Oracle
Opening Keynote | An Enterprise Cloud for Business-Critical Applications
Abiquo
Day 2 Keynote | The Enterprise Cloud Tightrope - Balancing for Success
Akamai
Day 3 Keynote | The DNA of an Enterprise Cloud
DIAMOND SPONSOR:
Oracle
Many Clouds, Many Choices'Cloud
PLATINUM PLUS SPONSORS:
Abiquo
Enterprise Cloud Best Practices - Town Hall - Join the discussion…
PLATINUM SPONSORS:
Intel
Progressing Toward the Federated, Automated and Client-Aware Cloud
New Relic
How to build an app with Twitter-like throughput
Rackspace
Computing in the Cloud Era
GOLD SPONSORS:
Gale Technologies
Practical Cloud Migration
IBM
Re-think IT. Re-inventing Business.
Intel/McAfee
Identity Driven Security in the Cloud
PerspecSys
Hackers Hackers Everywhere, Is My Public Cloud That Safe?
Red Hat
Unlock the Value of the Cloud
SHI
Mission Critical Applications and the Cloud - Myth or Reality?
SoftLayer
Not Your Grandpa's Cloud
Terremark
Integrating Enterprise Clouds
VMware
Upgrade to a vCloud
POWER PANELS:
Cloud Expo Silicon Valley: CTO Power Panel
Cloud Expo Silicon Valley: CEO Power Panel
Cloud Expo Silicon Valley: Cloud SuperStars Panel
Cloud Expo Silicon Valley: CloudNOW Panel
Click For 2010 West
Event Webcasts
Cloud Expo & Virtualization 2011 East
DIAMOND SPONSOR:
Dell
Dell & VMware Deliver the Enterprise Hybrid Cloud
PLATINUM PLUS SPONSORS:
Abiquo
Are Financial Services Organizations Risking Security by Avoiding Cloud Computing?
Oracle
From Consolidation to Enterprise Private PaaS
PLATINUM SPONSORS:
Intel
Driving the Transformation to Next Generation Cloud Data Centers
Rackspace
The Inevitability of an Open Cloud
GOLD SPONSORS:
CA Technologies
Follow YOUR path to Cloud Computing
Interxion
Who Keeps the Cloud in the Air?
Microsoft
Patterns for Cloud Computing
PerspecSys
War in the Clouds: Are you ready?
ServiceMesh
The Big Win: Stop Playing Small-Ball with Your Cloud Strategy
Terremark
Evaluating Enterprise Clouds
Xiotech
Cloud Storage: Myths and Realities
POWER PANELS:
Cloud Expo New York: CTO Power Panel
Cloud Expo New York: CEO Power Panel
Cloud Expo New York: CMO Power Panel
Cloud Expo New York: Wrap-Up Power Panel
Click For 2010 West
Event Webcasts
Live Google News by SYS-CON!
Top Three Links You Must Click On


CF Tips & Techniques
May 1998 Tip and Tricks
Referencing Individual Elements of a CFQUERY Result Set

By: Ray Camden
Sep. 17, 2003 12:00 AM

CF 3.x now allows you to directly reference values stored within a CFQUERY result set. To reference a value stored in query myquery in column mycolumn at row 4 requires the following syntax:

#Myquery.mycolumn[4]#

Steve Drucker President, Fig Leaf Software
sdrucker@figleaf.com

Taking Control of your Parameters
To increase performance of Cold Fusion applications and to write more readable, stable and portable code, it is best to include the applicable scope with each reference to a variable. But sometimes we don't know ahead of time whether a template is going to be called from a form or with a URL so we don't know whether to use Form.MyVariable or URL.MyVariable to obtain the value of MyVariable. I prefer to write code that, in a sense, "declares" variables near the top of each template by testing for the existence of a form or URL variable and then setting Variables.MyVariable to the value of what is found. Should neither a form nor a URL variable be found, I like to specify some alternate program flow, possibly using new code nested in a CFELSE tag, a CFLOCATION or CFINCLUDE tag.

The code for my "declarations" might look something like this:


<CFIF IsDefined("Form.MyVariable")>
 <CFSET Variables.MyVariable = Form.MyVariable>
<CFELSEIF IsDefined("URL.MyVariable")>
 <CFSET Variables.MyVariable = URL.MyVariable>
<CFELSE>
 <CFINCLUDE TEMPLATE="ParameterError.cfm?VariableMissing=MyVariable">
 <CFABORT>
</CFIF>

Once this code has run, we can refer to "Variables.MyVariable" without having to be concerned about whether the variable was posted from a form or appended to a URL. This becomes more important as the complexity of your code grows and you start using more CFINCLUDE tags.

You might be wondering why I don't just use a CFPARAM tag. There are some subtleties in how the CFPARAM tag works that prevent it from accomplishing all our objectives. Remember that we want to be able to set the value of Variables.MyVariable to the value of whatever was sent in, or possibly a default, so that we can refer to MyVariable explicitly within the Variables scope. CFPARAM does, indeed, set a default value to Variables.MyVariable if a variable called MyVariable is not found on either the URL or form that called the template. But what happens if you send in a URL or form variable called URL.MyVariable or Form.MyVariable and then try to reference Variables.MyVariable? CFPARAM does nothing at all if a Form or a URL variable of the specified name is sent in, so Variables.MyVariable goes undeclared and your template will crash when you try to reference Variables.MyVariable.

Perhaps in a future release of Cold Fusion, we will be able to declare all variables within the Variables scope in one clean little tag.

Erik Midtskogen Firm Support Software, Inc.
erik@firmsupport.com

Saving State by Passing Values Between Forms
1) On form submission, save all form fields into session variables

2) Use the JavaScript onChange event to save out form field contents into a hidden form contained within a hidden frame

3) Use the CF FORMFIELDS collection to dynamically replicate the form fields on each CFM page

Generally, I dont like to use session variables to hold a large amount of data, so option 1 is out. We've used options 2 and 3 successfully:

Option 2: Hidden Frame technique

Step 1: You need a frameset containing a hidden frame


<FRAMESET ROWS=*,0>
 <FRAME NAME=dataframe SRC=myform.cfm>
 <FRAME NAME=hiddenframe SRC=savestate.cfm>
</FRAMESET>

Step 2: The hidden frame should contain an HTML form containing hidden form fields for all the data to be submitted to CF for processing


<FORM ACTION=savedata.cfm METHOD=POST>
 <INPUT TYPE=hidden NAME=myfield VALUE=>
</FORM>

Step 3: Use the JavaScript onChange Event to write out changes to the form in the persistent hidden frame.


<FORM ACTION=page2.cfm >
<INPUT TYPE=text NAME=myfield SIZE=10 onChange=parent.hiddenframe.document.forms[0].myfield.value=this.value>
<INPUT TYPE=submit VALUE=Next Page>
</FORM>

Step 4: For final form submission to be written to the database, submit the HIDDEN form


<FORM>
 <INPUT TYPE=button onClick=parent.hiddenframe.document.forms[0].submit() VALUE=Write to DB>
</FORM>

Option 3: Dynamically replicate the form fields on each sub-form page
Cold Fusion supports a form element called FORMFIELDS. This form variable will contain a comma-delimited list of form elements passed to an action page. Using the CFLOOP tag, you can easily parse this list, outputting variables and their values into hidden form elements. This solution is more robust than the one previously described, could easily be turned into a custom tag and does not require JavaScript support.


<FORM ACTION=page3.cfm METHOD=POST>

 <CFLOOP LIST=#formfields# INDEX=iindex>
  <CFOUTPUT>
   <INPUT TYPE=hidden NAME=#iindex# VALUE=#evaluate(form. & iindex)#>
  </CFOUTPUT>
 </CFLOOP>
</FORM>

Steve Drucker
President, Fig Leaf Software
sdrucker@figleaf.com

JavaScript Read-Only Fields
Read-only fields only recently became part of the HTML 4.0 specification. You can, however, code this same level of functionality into your applications today by leveraging JavaScript events.

The JavaScript onFocus event executes javascript code whenever a user tabs into a form element. Its cousin, the onChange event fires whenever a user modifies the contents of a form field. Used together, these event handlers can render a field read-only such that only JavaScript program code may dynamically change the contents of a field. The example below works for text and password form input objects.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">

<HTML>
<HEAD>
 <TITLE>Untitled</TITLE>

 <SCRIPT LANGUAGE="JavaScript">
  var savedval=""

  function myreadonlyfield(obj,mode) {

   if (mode==1) { /* onfocus event */
    savedval=obj.value
   } else {
    alert("This is a read-only field and may not be changed")
    obj.value=savedval
   } 

  }
 </SCRIPT>  

</HEAD>

<BODY>

<INPUT TYPE="text" NAME="myfield" onFocus="myreadonlyfield(this,1)" onChange="myreadonlyfield(this,2)" VALUE="5">
<INPUT TYPE="submit">

</BODY>
</HTML>

Steve Drucker
President, Fig Leaf Software
sdrucker@figleaf.com

One Form Please
When building data entry applications, it is almost always better to develop one HTML/CFML form for viewing, adding and editing records than it is to build separate forms for each function. Why? Because your application will be easier to maintain. Applications have a way of evolving over time. New fields get added, old fields get "retired" and so on. If you have to make a change to some aspect of your data entry application, it's better to have to change the code in only one template rather than having to go to two or three.

Leon Chalnick
President, Professional Presence Providers, Inc.
lchalnick@prprpr.com

Variables and Data Sources
Use a variable to name the data source(s) used in your applications. Instantiate this variable in your application.cfm file. If, for any reason, you need to be able to quickly and easily change the name of a datasource, it will be much easier to change it if you have to go to only one place.

Leon Chalnick
President, Professional Presence Providers, Inc.
lchalnick@prprpr.com

Stop Runaway Keys
When your application takes form submissions by writing the form data into a database which automatically generates unique keys, it's important that you do something to prevent the user from submitting the same form over and over. If you do nothing to prevent this, a user can submit a form full of data (creating a record into the database), hit his browser's Back button and submit the form again, thus creating a duplicate record. A relatively simple approach to dealing with this is to generate the unique key for the new record before the data entry form is displayed by your application. Store this unique key in a hidden field in the form. When the user submits the form, use a "select" query to see if the record already exists in the table. If it does, let the user know. If the record doesn't already exist, then it's safe to add it.

Leon Chalnick
President, Professional Presence Providers, Inc.
lchalnick@prprpr.com

Cryptic Killer
You only need to hear this horror story a few times before it really sinks in. You work for three months on a killer Cold Fusion application. You are about to bring it to your first potential buyer when you decide it may be safer to encrypt it first. You drop to a DOS prompt, encrypt your code and then realize that you encrypted your only copy.

If you decide to encrypt your Cold Fusion work, copy it to a different directory. Even better, copy it to a different machine. I make it a habit to only encrypt files from our network server on my personal machine's desktop.

Raymond Camden
morpheus@deathclock.com

Don't Mess with my Parameters
If your site uses URL variables, i.e., product_display.cfm?ProductID=5, always be careful to design your code to handle incorrect values for the URL variables, or the complete lack of those variables. For example, whenever I see a site that passes along information via the URL, the first thing I am tempted to do is screw around with those variables. In the example above, if this were my first time on the page product_display.cfm, I may completely strip out the ?ProductID=5 from the URL to see how the application handles it.

The same could be said for form variables as well, although it is much harder for a malicious visitor to screw around with those. For example, I may view the source on your search page and see that it's sending a few hidden form fields to configure the search engine. I could create a form on my server that calls your application but with my own values.

Published Sep. 17, 2003— Reads 6,672
Copyright © 2003 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
About Ray Camden
A longtime ColdFusion user, Raymond is a co-author of the "Mastering ColdFusion" series published by Sybex Inc, as well as the lead author for the ColdFusion MX Developer's Handbook. He also presents at numerous conferences and contributes to online webzines. He and Rob Brooks-Bilson created and run the Common Function Library Project (www.cflib.org), an open source repository of ColdFusion UDFs. Raymond has helped form three ColdFusion User Groups and is the manager of the Acadiana MMUG.

Add Your Feedback

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON Featured Whitepapers

ADS BY GOOGLE

Breaking Java News
Grupo Elektra Announces 50% EBITDA Growth to Historical Maximum of Ps.2,556 Million in 4Q11
Allied Motion Announces Record Profit for the Quarter and Year Ended December 31, 2011
Parents Are Giving The Enclave by William Lyon Homes High Marks
Maxthon Mobile Adds 'Quick and Easy' Screenshot Capture to Easily Save, Send and Share Full Screengrabs and Pictures
Khronos Group Announces the KITE Initiative to Connect Industry to Education
Gundersen Lutheran Health System Shortens Invoice Processing Cycle, Achieves Touchless Pass with Brainware and Ascend
Rosedale in Azusa -- the Perfect Community for Extended Families
Hollywood Tans Sets March 10 as Its Fourth Annual "Season Premiere Day(TM)"
Maxthon Mobile Adds 'Quick and Easy' Screenshot Capture to Easily Save, Send and Share Full Screengrabs and Pictures
Horizon Receives Notice of Paragraph IV Certification Against Patents for DUEXIS(R)

ADVERTISE   |   MAGAZINE SUBSCRIPTIONS   |   FREE BREAKING-NEWSLETTERS!   |   SYS-CON.TV   |   BLOG-N-PLAY!   |   WEBCAST   |   EDUCATION   |   RESEARCH

.NET Developer's Journal - .NETDJ   |   ColdFusion Developer's Journal - CFDJ   |   Eclipse Developer's Journal - EDJ   |   Enterprise Open Source Magazine - EOS
Open Web Developer's Journal - OPENWEB   |   iPhone Developer's Journal - iPHONE   |   Virtualization - Virtualization   |   Java Developer's Journal - JDJ   |   Linux.SYS-CON.com
PowerBuilder Developer's Journal - PBDJ   |   SEO / SEM Journal - SJ   |   SOAWorld Magazine - SOAWM   |   IT Solutions Guide - ITSG   |   Symbian Developer's Journal - SDJ
WebLogic Developer's Journal - WLDJ   |   WebSphere Journal - WJ   |   Wireless Business & Technology - WBT   |   XML-Journal - XMLJ   |   Internet Video - iTV
Flex Developer's Journal - Flex   |   AJAXWorld Magazine - AWM   |   Silverlight Developer's Journal - SLDJ   |   PHP.SYS-CON.com   |   Web 2.0 Journal - WEB2
Apache   |   CMS   |   CRM   |   HP   |   Oracle Journal   |   Perl   |   Python   |   Red Hat   |   Ruby on Rails   |   SAP   |   SaaS

SYS-CON MEDIA:   ABOUT US   |   CONTACT US   |   COMPANY NEWS   |   CAREERS   |   SITE MAP
SYS-CON EVENTS:   |  AJAXWorld Conference & Expo  |  iPhone Developer Summit  |  Cloud Computing Conference & Expo  |  SOA World Conference & Expo  |  Virtualization Conference & Expo
INTERNATIONAL SITES:   India  |  U.K.  |  Canada  |  Germany  |  France  |  Australia  |  Italy  |  Spain  |  Netherlands  |  Brazil  |  Belgium
 Terms of Use & Our Privacy Statement     About Newsfeeds / Video Feeds
Copyright ©1994-2008 SYS-CON Publications, Inc. All Rights Reserved. All marks are trademarks of SYS-CON Media.
Reproduction in whole or in part in any form or medium without express written permission of SYS-CON Publications, Inc. is prohibited.
 
close this window