Home / Articles / Adobe ColdFusion / Developing a ColdFusion/J2EE Solution

Developing a ColdFusion/J2EE Solution

Chapter Description

This article kicks off in the midst of fictional Sonic Systems' web project. It shows how the aim in creating a project blueprint was to eliminate the possibility for changes in the architecture during development, and to help development go as smoothly as possible.

Editing Template Development

The final step in developing the Sonic application was to create the portlets that would be used to perform any tasks within the portal application, including customizing the portlet setup, logging into applications, and administering users within the application. The administrative interface was set up first to edit the database and users and groups within the system.

The Administrative Interface

To start, an administrative controller was set up. By appending the URL variable admin=true, the admin controller overrides the tab controller. This is done in the index.cfm by adding a <CFIF> statement:

<CFIF IsDefined("URL.Admin")>

The AdminIndex.cfm controller template takes a URL parameter called action. Within a <CFSWITCH> statement, a number of <CFCASE> statements include the appropriate file based on what is passed in the action URL parameter. Each of these included files is protected using Project Omega's bit-based permission template.

This security framework is a Project Omega tool that the team had used for many of their projects. Basically, every permission level is assigned a number that is a power of 2. These are the bit values: 1, 2, 4, 8, 16, etc. When a user logs in, the user's permissions are added together, and the resulting value is set to the SESSION.Permissions.userPermission variable. This value can then be tested to see if it contains the relevant bit value to access a certain template. A <CF_SECURE> tag can be used to perform such tests.


The REQUIREDPERMISSION attribute contains the bit value necessary to access the specified resource. These permission levels can be looked up in the database, as well as added to and edited. The USERPERMISSIONS attribute contains the user's permission level, and the FAILUREREDIRECT specifies where to redirect the user if the permissions are not adequate.

The existing administrative templates needed very minimal adaptation in order to work with the portal application. The admin=true URL variable just needed to be appended, and the existing design elements stripped out. This included editing of users, groups, and permissions. The only additional editing required was editing affiliations, the groups that contain portal design information.

For the affiliations add and edit page, Project Omega used <CFDIRECTORY> to obtain the possible headers, footers, stylesheets and portlet registries, and then <CFSELECT> to display the possibilities:

                      MESSAGE="You must select a header.">
     <CFOUTPUT QUERY="headerList">
          <OPTION<CFIF name EQ getAffiliation.Header>

The IncludeDirectory contains the location of the possible includes: where to find headers and footers. There is a similar variable for both registries and stylesheets. The FILTER attribute filters for all files containing "head" (footers filter by "foot" and stylesheets for ".css") in the filename. This will be important for designers to know when they add new headers and footers. Finally, the values returned are looped through to output the options, and a <CFIF> statement will select the option that is currently entered in the database; this effectively defaults the existing option.

Portlet Configurator

The portlet configurator allows users to edit how their portal is displayed—their PSML file, basically. This feature would require the creation of two templates: a PSML writer component and the DefinePortlets.cfm portlet. Together these templates will use Cold-Fusion's XML functions to edit an XML document object representation of the user's PSML file and save any changes to the actual PSML file and reset the user's preferences.

The PSML writer component will contain the following methods:

  • addPortlet(). Adds new tab to a user's PSML document object.

  • deletePortlet(). Removes a tab from the user's PSML document object.

  • writeNewPortlet(). Writes changes to a user's PSML document object.

  • savePSML(). Saves the user's PSML document object to the actual PSML file.

In all PSML editing functions (but not when saving the PSML file), the getUserPSML() method from the PSML reader component is invoked to return the ColdFusion XML document object of the user's PSML file. Within each, the appropriate ColdFusion functions are used to edit the document object.

The addPortlet() function first uses the ArrayAppend() and XmlElem-New() function to add a new <portlets> element, which will contain the tab information.

ArrayAppend(userPSML.portlets.XmlChildren, XmlElemNew(userPSML,"portlets")); 

XML child nodes are accessed in ColdFusion as an array. The <portlets> child nodes are what store the tabs, so adding a new element to this array with ArrayAppend() will be the same as adding a new element to the XML document object. The XmlElemNew() is used to create new XML elements—here you're actually creating the empty <portlets> element. These same basic techniques are used to create the title of the tab, the controller and insert portlets based on the TABTITLE, CONTROLLER and PORTLETSLIST (a comma-delimited list of portlets) arguments passed to it. The same arguments, USER (required), MEDIA, and LANGUAGE are also needed to retrieve the user's PSML file.

The writeNewPortlet() function saves information to an existing port-let. In addition to the USER, MEDIA, LANGUAGE, TABTITLE, CONTROLLER, and PORTLETSLIST arguments, this function also takes TAB, the index number of the <portlets> element being edited; AUTHARRAY, a two-dimensional array containing portlet log-in information; and AUTHKEY, an encryption key for encoding the user names and passwords.

The deletePortlet() function will remove a tab. This is done fairly simply by using ArrayDeleteAt() to remove the corresponding <portlets> element. The required argument, Tab, will specify the index of the tab to be deleted:


In all of these functions, the user's PSML is returned as a document object. This is done so that it can be further edited or saved by the calling file. If it is to be saved, the user's PSML is passed to the savePSML() function.

<!--- find location of user's PSML file --->
<CFINVOKE COMPONENT="portal.components.userinfo"
   <CFSET Success = TRUE>
        <CFSET Success = FALSE>
<CFRETURN Success>

Here, the PSML passed in the PSML argument is converted back from its ColdFusion XML document object representation into a string using the ToString() function. The PSML location is retrieved using the now familiar getUserPSML() function of the userinfo component. Finally, this method tries to save the file to this location using <CFFILE>. Depending on whether it succeeds or fails, a Boolean value is set to the Success variable, which is then returned.

Once this component was completed, the actual editing template could be created. To start, no anonymous use should ever be able to access this template; anonymous users get only what is set up as the default. A

<CFIF SESSION.User EQ "anon">
   You must log in to access this feature.

The first part of this template to be developed is the form. This form edits one tab at a time, and the first tab is the default. For each tab, the form will have a pull-down of controllers (from the controller registry), a tab name, and a list of all the portlets in the user's portlet registry—along with a check box, illustrating whether the user wants the given portlet on that tab and text fields to enter a user name and password if necessary. Figure I-3.8 shows what this form looks like.

Figure 3-8 Figure I-3.8 Each tab can be edited individually for each user.

In addition, this page will have a button to delete tabs, a link to create a new tab, and a pull-down to change the current tab for editing. Once this was all laid out and made dynamic, the actually processing information was entered at the top of the page.

A key aspect of developing portlets is to make sure that the form is submitted to the same page. This can be done by always linking to index.cfm in <A> and <FORM> tags, or else by using the CGI.SCRIPT_NAME variable. This would always resolve to the current page. This was important, because if a link went to another page, the user would leave the portal. However, by linking to the same page, the user would reload the portal page and include the portlet.

In order to do this, the form-processing information is included at the top of the page. For example, the tab-deleting feature is enclosed within a

<CFIF IsDefined("FORM.DPDeleteTab")>
   <!--- if last tab, don't allow --->
<CFIF ArrayLen(SESSION.UserPrefs.Tabs) LTE 1>
    You cannot delete your last tab.
<!--- Delete the friggin' tab already --->
<CFINVOKE COMPONENT="portal.components.PSMLWriter"
          <!--- save new PSML document for user --->
      <CFINVOKE COMPONENT="portal.components.PSMLWriter"
      <!--- if file was saved, re-write user's session --->
      <CFIF PSMLSaved>
         <!--- reset admin tab --->
         <CFSET SESSION.AdminTab = 1>
         <!--- send to home page
               (in case user is on tab just deleted) --->
         <CFLOCATION URL="#script_name#?CurrentTab=1">
         <P>There was a problem trying to delete this

The FORM.DPDeleteTab variable will only exist if the user has posted this page to the portlet. If so, this block will execute, first disallowing deletion of the last tab, and then invoking the PSML writer component to delete the portlet and save the PSML. If the PSML save is successful, the user's preferences are rewritten using the custom tags, and the user is redirected to the main portal page.

instant message

Note that the name of the form variable checked is unique: DPDeleteTab. This is to prevent other portlets from executing similar <CFIF> blocks. For example, if the name was just Delete, another portlet that deletes something different may be looking for that variable and actually execute. This was a problem Project Omega had learned about the hard way. The add and edit <CFIF> blocks were finally added, and the template was finished.


Remember that when portlets are loaded, there are many to a page. When passing FORM and URL variables, try to make them unique so as not to cause errors in other concurrently loading portlets.

Now that this was completed, the administrator needed to be able to link to these pages. To do so, a few steps were taken. First, two levels of permissions were added to the database: one for non-anonymous portal users and another for administrators. After that, the header template was edited. A series of <CFCASE> statements check the user's permissions. Depending on the result, a log-in file, a portal user navigation bar, or an administrative user navigation bar is included. Figure I-3.9 shows the three possibilities that will be included in the upper-right section of the page.

The final portlet Omega had to develop was the log-in one. This was a simple portlet that used the PSML reader components to retrieve all of the portlets a user had with log-in information. The user name and password were then output to hidden form fields and a button drawn for each portlet. By reading the portlet registry, the page to post log-in information could be obtained. Each button would then post this location with the TARGET attribute set to _blank, opening a new window.

Figure 3-9 Figure I-3.9 Depending on the type of user, the upper-right part of the portal screen will contain one of three navigation elements.

13. Creating a Real User and Testing | Next Section Previous Section

Adobe Press Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from Adobe Press and its family of brands. I can unsubscribe at any time.


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about Adobe Press products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information

To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.


Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites; develop new products and services; conduct educational research; and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.


If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email ask@peachpit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information

Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.


This site is not directed to children under the age of 13.


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information

If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.


Users can always make an informed choice as to whether they should proceed with certain services offered by Adobe Press. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.adobepress.com/u.aspx.

Sale of Personal Information

Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents

California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure

Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact

Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice

We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020