As we all know, ColdFusion has lots of features for website development and it also flexible. So, we can use it with other Programming Languages like Java & .Net. Here are some information about how ColdFusion interacts with them.


ColdFusion Interacts with Java

The standard ColdFusion installation allows the operation of ColdFusion as a WAR file or EAR file for operate to standalone application servers, such as Macromedia JRun, and IBM WebSphere. ColdFusion can also be deployed to servlet containers such as Apache Tomcat and Mortbay Jetty, but because these platforms do not support ColdFusion officially, they leave many of its features inaccessible.

Because ColdFusion is a Java EE application, ColdFusion code can be mixed with Java classes to create a variety of applications and utilize existing Java libraries. ColdFusion has access to all underlying Java classes, supports JSP custom tag libraries, and can access JSP functions after retrieving the JSP page context (GetPageContext()).

Prior to ColdFusion 7.0.1, ColdFusion components could only be used by Java or .NET by declaring them as web services. However, beginning in ColdFusion MX 7.0.1, ColdFusion components can now be utilized directly within Java classes using the CFCProxy class.
Recently, there has been much interest in Java development using alternate languages such as Jython, Groovy and JRuby. ColdFusion was one of the first scripting platforms to allow this style of Java development.

Although These facilities provided by ColdFusion. It has also some limitations to ColdFusion's ability to offer Java scripting:
  • ColdFusion MX 6.1 did not support usage of null value method parameters
  • Lack of Bean Scripting Framework plugin support
  • one cannot extend Java classes in ColdFusion

ColdFusion Interacts with .Net

ColdFusion 8 natively supports .NET within the (ColdFusion MarkUp Language)CFML syntax. ColdFusion developers can simply call any .NET assembly without needing to recompile or alter the assemblies in any way. Data types are automatically translated between ColdFusion and .NET (example: .NET DataTable → ColdFusion Query).

A unique feature for a J2EE vendor, ColdFusion 8 offers the ability to access .NET assemblies remotely through proxy (without the use of .NET Remoting). This allows ColdFusion users to leverage .NET without having to be installed on a Windows operating system.

The move to include .NET support in addition to the existing support for Java, CORBA and COM is a continuation of Adobe ColdFusion's agnostic approach to the technology stack. ColdFusion can not only bring together disparate technologies within the enterprise, but can make those technologies available to a number of clients beyond the web browser including, but not limited to, the Flash Player, Adobe Integrated Runtime (AIR), Mobile devices (SMS), Acrobat Reader (PDF) and IM gateways.


More Information visit ColdFusion Development Services.

While developing any software project, you should follow nice project management methods. This will make the programming easier and will help to minimize problems later on. This is also true for developing a project in ColdFusion.


Summary

It is important to plan things out before you start coding. You should establish the project requirements, flowchart the screens, set up your database, and then add coding. Finally, you test and format the page. You will benefit by shortening the time required to develop the project, as well as maintaining better control over the process.

Major steps as follows :-

  • Thoroughly define the requirements
  • Set up your database
  • Flowchart your screens
  • State actions for each page and input code
  • Test and trouble-shoot
  • Format the pages to look nice
  • Deliver on the Web
->Thoroughly define the requirements

Your goal is to satisfy the need of your clients or the user. Some projects consist of only one requirement, such as when the company needs a listing of employee records for human resources to administer. That is pretty straightforward.
In other cases, the desire is complex-like in the case of e-commerce. In such a situation, you need to outline that objective and its requirements into smaller pieces. For example in e-commerce, steps may be listing the products, using a shopping cart, and purchasing the product. You should define each product as a mini-project with separate specifications.

->Set up your database

ColdFusion usually accesses a server database for information used in populating a page. The database may already be in existence or you will set up your database as part of the coding process. You need to know the names of the tables you will use in your database, as well as the field names. You also need to note the type of fields, because that influences some of the ColdFusion coding punctuation.

Often, it is necessary to break a table into several relational tables. You must also know the primary and foreign keys of relational tables. It is essential to document the names and types of your database tables and fields as an aid for writing your ColdFusion code and SQL instructions.


->Flowchart your screens

Make a flowchart of your screens and state what each function does.
For example, if the goal of the project was to provide a way for people to find company employee information online, the screens would be:
  1. Welcome screen with choices of finding employee by name or department.
  2. Department screen with list of employees, with option of selecting one for details.
  3. Employee screen, with option to check for details.
  4. Detail screen for employee.
->Tell what actions are taken in each page

From the flowchart, take each page and tell what actions are taken. For example, the Department screen queries the database for a list of employees in the designated department. Each employee name provides a link to a Details page.


You can then add the code for these specific actions. Doing it in this manner gives you a better picture of what you are to code and minimizes coding errors.


->
Test and trouble-shoot

Although you can try to test the whole project, it is often easier to check out each snippet of code, one at a time, to make sure the coding and database access is correct.


->Format the pages to look nice You can format the pages to make them pleasing to use, as well as to confirm to the company look. You can add color, images and such.

->Deliver on the Web

Finally, you must put your database and files on the Web and try them out in the real world. You need to have your Web administrator set up your database for use with a
ColdFusion server.

Benefits of All Steps

Following a systematic approach helps you to avoid the wasting of time on trouble-shooting. In a complex project, it is essential to maintain a good overview so that you do not lose control of the coding process.



For More Information visit our ColdFusion Development Services.

Semaphore is specialized in ColdFusion Web Development. ColdFusion is our development tool of choice for rapidly deploying web applications, dynamic web sites, intranets or e-commerce sites.

Semaphore has been offering quality ColdFusion Development services. Our ColdFusion Developers consistently push the envelope of ColdFusion Programming to create robust solutions that are fast, modular, stable, easy to use and easy to upgrade. Our consultants can tackle any ColdFusion problem - from the most minor of updates, to the most complex ColdFusion enterprise applications. We are well versed in the full spectrum of ColdFusion technologies, including ColdFusion versions 3 through MX 7, Rich Internet Applications, the ColdFusion API.

Semaphore's ColdFusion Development Services:
  • Conversion from HTML to PDF and FlashPaper ColdFusion Web Development
  • Client-side code generation, especially for form widgets and validation
  • Platform-independent database querying via ODBC (Open Database Connectivity) or JDBC (Java Database Connectivity).
  • Data retrieval from common enterprise systems such as Active Directory, LDAP (Light Weight Directory Access Protocol), POP (Post Office Protocol), HTTP (Hyper Text Transfer Protocol), FTP (File Transfer Protocol), Microsoft Exchange Server
  • Client and server cache management
  • Session, client, and application management
  • File indexing and searching service based on Verity K2
  • XML parsing, querying, and validation
  • Server clustering
  • GUI administration
  • Task scheduling

For More Information visit our ColdFusion Development Services.

Know the rules for naming variables.

The golden rule concerning naming variables in your ColdFusion applications is simple:

Variable names must begin with a letter and can contain only letters, numbers, and the underscore character.

In addition to these two rules, there are several additional guidelines that you should follow to minimize potential problems in your applications:

  • Variable names are not case sensitive. In the interest of good style and readability, however, you should keep the case of your variable names consistent.
  • Always try to use descriptive terms for your variables. It might seem like a pain, but you will be grateful when it comes time to debug or add a new feature later on down the road.#
  • Avoid using variable names that may be reserved words in SQL. Words such as Time, Date, and Order may cause errors when querying databases.
  • Avoid using variable names that are the same as ColdFusion variable scopes. Names such as Application, Attribute, Caller, CGI, Client, Cookie, Form, Variable, Request, Server, Session, URL, and Query.
  • Avoid choosing variable names that end in _date, _eurodate, _float, _integer, _range, _required, or _time. These are reserved suffixes for server-side form validation variables and can cause naming conflicts.
  • Use ColdFusion variable names that match the corresponding fields in the database. If your application interacts with a database, this makes your code clearer.
Scope your variable.

ColdFusion supports a number of different variable scopes, where scope refers to the context in which the variable exists within an application. The scope encompasses where the variable came from (such as a form field, a URL, etc.), how it can be used, and how long it persists. When you refer to a variable in your code, you can refer to it using just the variable's simple name (MyVar) or by its fully scoped name (Scope.MyVar).

Visit web.oreilly.com for a complete list of O'Reilly's books about Web and Internet technologies.

Because ColdFusion supports different variable scopes, the potential exists for having like-named variables of different scopes within an application. ColdFusion allows you to deal with this potential conflict in two ways.

One way to handle potential variable conflicts is to always provide the variable scope when referencing a variable. For example, a URL variable should be referenced as URL.MyVariable, while a form variable should be referenced as Form.MyVariable. Using the variable scope has two additional benefits. First, it makes your code more readable, by identifying the variable scope right along with the variable. That way, when you look through your code, you know in exactly what context a particular variable is used. The second benefit has to do with performance. When ColdFusion encounters a scoped variable, it is able to process the code faster because it does not have to take time to determine the variable's scope.

The second way to deal with potential variable conflicts is to let ColdFusion handle them. When the ColdFusion server encounters an unscoped variable, it attempts to evaluate it in a specific order. Because application, server, session, attribute, caller, and request variables must always be scoped, they are not included in the order of evaluation, which is as follows:

As you might imagine, allowing ColdFusion to resolve potential conflicts can lead to unexpected results. For example, you might refer to a variable thinking that you are getting a URL variable, but ColdFusion resolves it to a local variable that has the same name. Of course, you can avoid this problem by choosing your variable names more carefully. But to make things even clearer, I recommend that you always scope your variables.

Lock all reads/writes of application, session, and server variables.

Because ColdFusion is a multithreaded application server, it is possible for multiple threads to attempt to access the same variable at the same time. For application, session, and server variables, this is an issue. Because each of these persistent variable types is stored in the ColdFusion server's RAM, the potential exists for the memory to become corrupted as multiple threads attempt to access (read or write) the same variable concurrently and end up colliding.

When a collision occurs, all sorts of problems can result. I've heard of everything from users receiving other users' data, to server instability, to crashing the ColdFusion application server. Because memory space is involved, the results of a collision are, at best, unpredictable.

Fortunately, ColdFusion has a mechanism for managing concurrent access to specific variables or chunks of code know as locking. Locking can be broken down into two types, exclusive and read-only. Exclusive locking means that ColdFusion single-threads access to a particular variable or chunk of code:



In this example, the list of field names is output on a single line. Next, a list loop is used to loop over the list of field names and output each one along with its associated value. The value for each form field is obtained using the Evaluate() function. Note that the special validation form fields (i.e., ones that have names that end with _date, _time, etc.) are not present in the Form.FieldNames variable. They are, however, present in the Form structure we discussed in the first method.

This means only one thread at a time is allowed to access code that has been exclusively locked. Any other threads that attempt to access an exclusively locked block of code are queued until the initial request completes. Exclusive locks must be used (notice I say must, and not should) when writing to application, session, and server variables. Because exclusive locks single-thread concurrent requests, they have a negative impact on performance. For this reason, it is important to use them sparingly.

The other type of lock you can use is a read-only lock. When you place a read-only lock around a particular piece of code, ColdFusion does not automatically single-thread access to that code:



What it does do is prevent an exclusive lock from being placed on the code while it is being read from. In other words, if you have a read-only lock placed around a chunk of code that reads a shared persistent variable, multiple threads can read the variable's value, but a concurrent request to write to the variable will not be processed until the read operations complete. Conversely, if an exclusive lock is already in effect, a read-only lock will wait until the exclusive lock is released before proceeding. Because of this, read-only locks do not generally result in degraded performance. Read-only locks should be used anytime you read data from a shared persistent variable.

There is a lot more to locking than presented in this tip. Although I've covered the basics here, a complete discussion can be found in my book Programming ColdFusion (O'Reilly).

Alternate row colors in dynamically generated HTML tables.

On of the most frequently asked questions by those new to ColdFusion development is how to alternate the row colors for dynamically generated HTML tables. There are several ways to do this, however, the easiest is to use the IIF() and DE() functions as shown in the following example:



The row color is alternated by using the IIF() and DE() functions along with the MOD operator to determine whether or not the row number for the current record being output is odd or even. Depending on the outcome of the evaluation, one color or the other (in this case, two shades of gray) is used as the background color for the current row. Because hex color codes are supposed to begin with a pound sign (#), we have to create an escape sequence before we call the IIF() function. This is done by doubling up on the first pound sign.

Obtaining a list of form fields and their values.

One question I see posted over and over again in the ColdFusion Support Forum asks how to obtain a list of all form fields and their associated values submitted by an HTML form using the POST method. This technique is often used to work with dynamically created form fields, in situations where you do not necessarily know the names of the form fields being passed.

There are two ways to obtain a list of form field names and their values:

The first method uses a special ColdFusion structure, named Form (introduced in v4.5) that contains each form field name and its associated value. To obtain a list of all form variables within the Form structure, you could use code like this:



The code uses a collection loop to loop over the Form structure. Each variable name and its associated value are output in an HTML table.

The second method for obtaining a list of every form variable passed to a template involves a special form variable called Form.FieldNames. This variable is automatically available to any ColdFusion template and contains a comma-delimited list of form field names that have been posted to the current template.



In this example, the list of field names is output on a single line. Next, a list loop is used to loop over the list of field names and output each one along with its associated value. The value for each form field is obtained using the Evaluate() function. Note that the special validation form fields (i.e., ones that have names that end with _date, _time, etc.) are not present in the Form.FieldNames variable. They are, however, present in the Form structure we discussed in the first method.

Avoid redirection with CFLOCATION when using cookies.

Due to the way ColdFusion assembles dynamic pages, you should not attempt to use the CFLOCATION tag within a template after a cookie variable has been set. Setting a cookie variable and using CFLOCATION afterward results in the cookie not being set. If you need to redirect to a different template after setting a cookie, consider using the CFHEADER tag instead, as in:

The CFHEADER tag generates a custom HTTP header with a Refresh element that contains the number of seconds to wait before refreshing the page as well as the URL of the page to retrieve when the refresh occurs.

Use stored procedures for database queries whenever possible.

Most enterprise level databases (MS SQL Server, DB2, Oracle, Informix, Sybase) support creating special programs within the database called stored procedures.

Stored procedures allow you to encapsulate SQL and other database-specific functions in a wrapper that can be called from external applications. There are several reasons why you should use stored procedures whenever possible in your applications:

  • Stored procedures execute faster than identical code passed using the CFQUERY tag because they are precompiled on the database server.
  • Stored procedures support code reuse. A single procedure only needs to be created once and can be accessed by any number of templates--even different applications and those written in other languages.
  • Stored procedures allow you to encapsulate complex database manipulation routines--often utilizing database specific functions.
  • Security is enhanced by keeping all database operations encapsulated within the stored procedure. Because ColdFusion only passes parameters to the stored procedure, there is no way to execute arbitrary SQL commands.
  • Many enterprise level databases support the return of more than one record set through stored procedures. This simply isn't possible using the CFQUERY tag.

Avoid assigning user-defined functions (UDFs) to persistent variable scopes.

The code for user-defined functions can be written inline, at the beginning of a template, or more commonly, contained in a separate file that is included at the beginning of the template via the CFINCLUDE tag. Advanced developers new to UDFs may be tempted to assign frequently used functions to one of the persistent scopes (Application, Session and Server scope) in an attempt to improve performance. Although this sounds tempting, it should be avoided.

The first problem with this technique has to do with locking. Because reads and writes to persistent variables must always be locked, any time you want to reference a UDF in your code, you'll need to include two extra lines of code to lock the variable. This can get to be a real pain with frequently used functions.

The second reason to avoid this technique is that it wastes RAM. Each function you store in a persisitent variable takes RAM that could probably be put to better use elsewhere in your application. The Server scope is a particularly bad place to put UDFs as Server variables persist until the ColdFusion Application Server is rebooted.

It makes much more sense to keep all of your frequently used UDFs in a single "function library" template that can be included via CFINCLUDE only in the templates where the functions are needed. If you find you use functions from your library throughout your application, you have the option of placing a single CFINCLUDE in your Application.cfm template. The minor overhead of having to include the function library template easily offsets the inconvenience of locking all function calls and wasted server resources of storing the function in a memory resident variable.

Detecting WAP- and WML-enabled devices.

ColdFusion is increasingly being used to deliver content to WAP (Wireless Application Protocol) enabled devices such as cell phones and PDAs. One question I'm frequently asked is how to detect when a request to the server is made by a WAP- and WML- (Wireless Markup Language) enabled device, so that WML content can be delivered to the user instead of HTML. The answer is to use the CGI variable HTTP_ACCEPT to see if the user's browser is capable of receiving content with the MIME type text/vnd.wap.wml. The following code should be placed at the top of any page you want the check to occur on:



If the user's browser does accept the MIME type, we know the user is coming to the site with a WAP- and WML-enabled device, and he or she is rerouted to an appropriate page that generates WML content.

Take advantage of the Verity K2 server in ColdFusion 5.0.

Since version 2.0, ColdFusion has included advanced indexing and searching capabilities using a bundled version of Verity's popular search technology via the VDK (Verity Developer's Kit). In addition to the VDK, ColdFusion 5.0 comes with a restricted version of Verity's enterprise level K2 server. K2 server offers features that appeal to clustered and large-scale sites, such as simultaneous searching of distributed collections, concurrent queries, and an overall performance gain over the VDK engine. Setting up and administering the K2 server takes a bit of work, but is well worth the results. For more information, consult the Advanced ColdFusion Administration book that comes with the official ColdFusion documentation.

For more information visit our ColdFusion Development Services.