Using of ColdFusion to create dynamic WAP pages is much easier than using other languages like PHP, ASP or JSP (a very hard one!). In fact, ColdFusion is a very good for one new to the WAP world to learn how to create dynamic WAP pages because it is very easy to learn.
Before we begin, keep these things in mind:
- You should have experience with HTML, the Web, ColdFusion and WML.
- We recommend that you use ColdFusion 4.5 Pro or ColdFusion 5 Pro. Note that we do not recommend that you use ColdFusion MX to start with. The reason is very simple – ColdFusion MX is harder to control. But if you are confidant that you can use the MX version, then you should use it.
- You need a WAP browser and a text editor. Your choice of WAP browser depends on your experience, but we recommend that you use the NOKIA WAP TOOL KIT, ERICSSON WAP TOOL KIT or the easy-to-use WIN WAP Pro. You’ll also need a text editor, and our recommendation is to use Notepad, or ColdFusion editors like ColdFusion Studio MX, DreamWeaver MX or HomeSite +.
- In this article we assume that you are using Windows 98, PWS, ColdFusion 5 Pro and Notepad.
- You can download ColdFusion 5, NOKIA WAP Tool Kit, ERICSSON WAP Tool Kit and WIN WAP from the following sites:
http://www.allaire.com
http://www.nokia.com
http://www.ericsson.com
http://www.winwap.com
Creating your First Dynamic WAP Page Using ColdFusion
You need to create a new folder in your Web server’s root directory with the name “ColdFusion.” All pages will be saved in this folder.
Open Notepad and type:
-==-
Save this file (with name of CFWAP.CFM) to your server’s root directory (for example, PWS and IIS’s root directories are C:INETPUB|WWWROOT).
We strongly recommend that you make a new directory in your Server’s root directory with the name of ColdFusion.
After saving the file, check that the web server and ColdFusion servers are running.
If they are, then open your WAP browser and write http://127.0.0.1/coldfusion/cfwap.cfm (this is a just an example).
You will see some thing like this:
If you don’t see preview as shown above in your WAP browser, make sure that:
- Your web server and ColdFusion server are RUNNING.
- You typed the address CORRECTLY in WAP browser’s address bar.
- You typed all the given code CORRECTLY in the file.
- Your web server and ColdFusion servers are ATTACHEDcorrectly.
Now we are going to learn how this file works.
You can see that first line in our file is
<CFCONTENT Type=”text/vnd.wap.wml”>
<CFCONTENT> is ColdFusion’s tag and it takes many attributes, but only the Type attribute is required.
With the <CFCONTENT> tag we tell the server to create given MIME Type’s page only.
(It is very important that you know about MIME (Multi Purpose Internet Mail Extension). You can find more information about MIME in RFC 2048, which can be found at http://www.rfceditor.org and by using Google with “MIME Types” as your keywords) Always remember that this line is should appear as every dynamic WAP page’s first line. If you not do it then the WAP browser can’t display your WAP pages.
The next few lines include WML codes and we do not define the WML code here because our mission is to provide Information about WAP + ColdFusion.
Lines number 8,9,10 have few ColdFusion tags:
<CFSET My_Name = “Amanat Ali Goher”>
<CFOUTPUT>
My Name is #My_Name#
</CFOUTPUT>
In line number 8 we create a variable called My_Name and give it the value “Amanat Ali Goher” by using the <CFSET> tag. This tag is used to create and assign a value to a variable.
To display our variable values, we use the <CFOUTPUT> tag as in line number 9.
To display the variable in our pages, we use the variables name with starting and ending with the # sign. It is necessary and you can see it in the example in line 10.
Note these things
- When you use <CFSET>, all rules of variable naming should obey usual naming conventions (variable names can’t start with number, etc.)
- The ending tag </CFOUTPUT> of <CFOUTPUT> is necessary.
- To print a variable’s value, the variable must appear between <CFOUTPUT> and </CFOUTPUT> with start and ending # (pound) signs, or else an error will occur.
Let’s move on to the next example.
Type the following code into Notepad or any text editor of your choice:
-==-
Next
Now it’s time to make a guestbook with our WAP pages. You know that guestbook is very important in a Web/WAP site. If you can make a guestbook, you can also make an order form.
Save given file as wmlform.wml in your server’s root directory:
-==-
Now we should make a more ColdFusion template, which will process submitted information.
This code will create file called “user_comments.txt” in your WEB Server’s root directory. This file will have all submitted Comment.
-==-
You can find comments in user_commets.txt file in you Root Directory.
Note: This code is very simple don’t try this is at commercial web/WAP site.
For more information please feel free to contact me any time.
Written by Amnat Ali Goher. Send your comments to yadish_sahar@hotmail.com.