May 26, 2019
Hot Topics:

Enrich Your Applications with JSP Components

  • July 26, 2005
  • By Michael Klaene
  • Send Email »
  • More Articles »

Rich Components with pragmaticObjects

Making the leap from the world of desktop applications to web-based applications usually means a sacrifice in terms of functionality. Components such as tabbed panes, context-sensitive menus, and tree menus are thick client standards, but it is difficult to duplicate these objects in a web environment. The last project we will look at, pragmaticObjects, provides a number of web components, made available through a set of JSP tags, to rival the look and capability of desktop components. Almost every Web application requires some sort of navigation between pages. Typically, accomplished with the standard HTML hyperlink, there is significant room for improvement in this area. The current set of components that pragmaticObjects provides include an outlookBar similar to what you might see in Microsoft Outlook, a controlPanel that mimics a Windows control panel, and a tree capable of providing context-sensitive menus for each of its nodes.

The pragmaticObjects Web site demos each of these components. To use them, download and add the pragmatic-controls.tld and pragmatic-controls.jar to your application. In addition to these files, you might require one or more XML files (the downloadable demo programs include samples of each of these) that can be used to configure the components. Public Java APIs are available if there is a need to modify the components at runtime.

We will add two components from this project to the sample application. First, a frame is added to display an outlookBar. This component is configured using the same outlook-bar.xml configuration file provided with the demo. Below is an image of what this outlook bar looks like. Clicking on any of the tabbed panes will bring that pane to the forefront. Each element within a pane will lead you to the URL that you specify.

Sample Outlook Bar

The result is a rich-looking component that consumes very little screen real estate. This component is configured to access a resource file, which allows you to support internationlization. The JSP tag markup contained in outlookMenu.jsp is listed below. With all pragmatic components, when the tag is executed, it will look for an attribute by that name in the current HttpSession. If no session variable exists by that name, it will produce one.

   <pragmatic:outlookBar configXmlPath="WEB-INF/outlook-bar.xml"
                         language="<%= (String)

As mentioned previously, a powerful capability of these components is that you can create them at runtime using their Java APIs. To demonstrate, a tree component will be added programmatically. Have a look at the following Java class called EmployeeTree. It contains a single method called buildTree that builds a tree component based upon the same employee list that we used for the DisplayTag table. We obtain this list from the ServletContext, pass it to the method that builds, then returns, a tree menu. The resulting tree will display all employees, grouped by their respective departments. In addition, the tree component has the ability to provide context-sensitive menus. By right-clicking a node, you can provide users with a list of menu items. We create two context menus, one for employee nodes and another for nodes representing a department, by referencing a context-menu.xml configuration file. The buildTree method assigns these context menus to the correct node. The following scriplet in our JSP creates the tree and the context menus that go along with it:

if (session.getAttribute("tree") == null) {
   //Load from our defined XML file using pragmaticObjects API
   //because menu items won't change...
   ContextMenu empMenu =
      new ContextMenu().loadFromXml(application.getRealPath(
   List employeeList =
      (List) application.getAttribute("employeeList");
   //Our defined method to conceal the tree-building logic...
   Tree tree = empTree.buildTree(employeeList);
   //Add menus to session...

Finally, you add the necessary JSP tags to display the pragmaticObjects tree component as shown below. Main.jsp contains all of the JSP tags that I've covered in this article, with the exception of the pragmaticObjects outlookBar that you placed in a separate frame.

<table width="100%" border="0">
      <td valign="top" width="15%">
         <pragmatic:tree-body treeConfigXmlPath="WEB-INF/tree.xml"
        resourceBundle="TreeMenu" language="<%=
           (String) session.getAttribute("LANG")%>"

Sample Tree Component

Click here for a larger image.

Putting it all together...


If you're developing JSP applications, I encourage you to take a look at the projects mentioned here in greater detail. Each one of them prove that JSP tags can provide a fast and easy way to enliven your Web applications.

About the Author

Michael Klaene is a Senior Consultant with Sogeti LLC. He has spent over 7 years in IT, specializing in J2EE and Oracle analysis and development.

Page 2 of 2

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date