Here are some of
Cold Fusion Tips that I would like to share with you which I have
tested and implemented in our intranet. There are javascript and Java
implementation too in this series and all have been tested to work
fine in NS 3 and 4 and IE4. Please find the tips valuable too and
drop by often for newer tips.
And, to help you migrate your scripts in MS Active Server Pages or
ASP to ColdFusion visit my Beginners ASP-CF
page. I tried to compare the two popular web scripting languages and
hope to convince you how simple it is to hand code web applications
in Cold Fusion than ASP.
I have Newer tips on my desk but I don't have enough time to convert
them all in HTML, but for now, I will leave you with my classic ones.
Enjoy!
Proper Comments
Crazy Color
Loop and Populate
Default CFM
Happy Birthday Java ticker and CFM
Proper
Comments
Ben Forta in
his book Web Database Construction Kit tells us to use
<!-- text --> as the format to comment text. It's
in the CF3.0 and CF3.1 online documentation too but actually it's <!--- text --->. It's three hyphen and not
2! Sounds pretty simple, but when you actually got used to using 2
and too lazy to add another hyphen the problem starts comming.
HTML comment tags
for 2 hyphen and without space after and before the tags is fine.
My experience with using 2 hypen caused me to find the problem after
several hours of testing the code and removing almost all the CFML
tags to locate the culprit. I could not find the problem until i noticed
I missed a space after the HTML tags and not on the CF tags i was
commenting.
[ top ]
Crazy Color
When you use font colors on a CFML variable
name, try to avoid using RGB coding in #RGB as in #FFFFFF for the
color white instead use 'White' as in this example or remove the pound
sign (#) altogether.
<FONT COLOR="#FFFFFF">#variablename#</FONT>
Or
<FONT COLOR="FFFFFF">#variablename#</FONT>#variablename#
If you are rushing
your project, that's good enough. If you'd rather stay with the convention,
escape it with the of use double pound sign.
<FONT COLOR="##FFFFFF">#variablename#</FONT>
[ top ]
Loop and Populate
When you have a predefined number of groups in a database and you
want to populate all the records segregated by groups you might think
making different sqls will do the trick. What if you have 8 groups,
then you will need to write 8 sqls! Image having 20.
The solution is to use
CFLOOP and a dynamically written queryname to be referenced in my selection
box later. The code is written below.
<cfset xnumber = 0 >
<cfloop index="asart" from="1" to="6">
<cfset xnumber = #xnumber# + 1>
<cfquery
name="ListPolicy#xNumber#"
datasource="File Leaves"
SELECT policy.policycode as code,
policy.PDFFILE as PDFFile,
policy.policy as policyname
FROM policy where 0=0
<cfif #xNumber# is 1> and policy.policycode='EP'</cfif>
<cfif #xNumber# is 2> and policy.policycode='WH'</cfif>
<cfif #xNumber# is 3> and policy.policycode='BW'</cfif>
<cfif #xNumber# is 4> and policy.policycode='ED'</cfif>
<cfif #xNumber# is 5> and policy.policycode='SP'</cfif>
<cfif #xNumber# is 6> and policy.policycode='WR'</cfif>
</cfquery>
</cfloop>
Take note of the
following:
- The name of the
query, ListPolicy#xNumber
on the first pass of the loop ListPolicy#xNumber becomes ListPolicy1,
then on the next sequence ListPolicy2 until the 6th loop, ListPolicy6.
- CFIF
on xNumber,
this will assign the first loop or the query ListPolicy1 to the group
EP, the next sequence assigns ListPolicy2 to WH and so on.
How does my selection
box looks like?
<form
name="isn1">EP
<select name="select">
<CFOUTPUT query="ListPolicy1">
<option value="#PDFFile#">#policyname#</CFOUTPUT>
</select>
<input
type="button" name="button"
value="Select and Go"
onClick="nav1(this.form)">
</form>
.
.
.
.
<form name="isn6">WR
<select name="isnf">
<CFOUTPUT QUERY="ListPolicy6">
<option value="#PDFFile#">#policyname#</CFOUTPUT>
</select>
<input type="button" name="button"
value="Select and Go"
onClick="nav6(this.form)">
[ top ]
Default CFM?
Most web servers use default.htm or default.html or index.htm or index.html
as the path default page. Now, what if you want a cfm file to be the
default page but would not want to re-set the default filetype setup?
Use javascript on
the default page to open a cfm file
<!--- file name:
default.html ----->
<!--- purpose : call default.cfm --->
<script language="javascript">
parent.location.href = "<strong>default.cfm</strong>";
</script>
<head>
<title>Start Page</title>
</HEAD>
[ top ]
Happy Birthday Java Ticker and
CFM
I would like a marquee effect on my page but the text must be dynamic.
You can include a classic ticker in your CFM file to integrate with
ColdFusion data.
This application determines
daily who's celebrating his birthday. Using a public domain vertical/horizontal
scrolling ticker, a cool effect can be achived. You can register the
applet in the CF Administration in order to embed an applet, but this
example does not use <cfapplet>.
First, you need to
sql to collect the data
<cfquery name="berday" datasource="bday">
SELECT [FNAME] & ' ' & [LNAME] AS Employee, BDAY
FROM EmpTable
WHERE Month([BDAY])=#Month(Now())# AND
Day([BDAY])=#Day(Now())#
</cfquery>
somewhere down in
your HTML, you introduce the JAVA applet and coldfusion tags.
<cfset #employees#
="">
<cfif #berday.recordcount#
is 0>
<cfset #employee# ="no celebrants today">
<cfelse>
Happy Birthday!!!
<applet code="ticker.class" width=430
height=20>
<param name=numMessages value="1">
<cfoutput query="berday">
<cfset #employees# = #employees#
& " * " & #employee#>
</cfoutput>
<cfoutput>
<param name=message1 value="#Employees#">
</cfoutput>
<param name=fontSize value="12">
<param name=bgColor value="blue">
<param name=fgColor value="yellow">
<param name=delay value="150">
</applet>
</cfif>
I saw this ticker.class
in http://www.gamelan.com, when you click on the ticker
the display scrolls backwards click again and it will return to its
normal mode. The JAVA parameters used are simple to crack.
PARAM NAME=numMessages
is constant
PARAM NAME=message1 is constant, the VALUE
is substituted by the collected data #employees#.
you can play with
the rest of the color setting for the rest of the required parameters.
I would like to apologize
that this site could not execute Cold Fusion scripts but I'm using
this technique in our intranet. Actually, the ticker is a news ticker,
for each message there is an appropriate link to the news details
but i removed the link and the class works very well without it. I
have not used the announcement to more than 100 celebrants, my fear
is that it might truncate values stored in the #employees#. The actual
implementation of the ticker is 1 message one value. But for a wider
scroll this would mean a longer delay before the next celebrant is
ever displayed. If you need the class email me and I will send you the zipped
file and some instructions and examples in using it.
[ top ]
Get your official help
at http://www.allaire.com/knowledgebase or visit http://forums.allaire.com
ColdFusion
is the best dynamic application server - EVER.
Copyright 1998 ASArt
mirror sites at AngelFire
and FortuneCity
for comments and suggestion:
asart@mail.be
Your are visitor
number:
|