J2EE, Struts and UIX in JDeveloper

Dr. Paul Dorsey, Dulcian, Inc.

Over the last few years, JDeveloper has evolved from a straightforward Java development product into a sophisticated Java 2 Platform Enterprise Edition (J2EE) development environment. The latest release, JDeveloper 10g is built for developing J2EE-compliant applications, which include the advantages of vast support from other vendors and the backing of recognized standards. As such, JDeveloper sits on a strong foundation. This paper will discuss three of the newest directions and additions to JDeveloper, namely its J2EE-compatible development environment, Struts technology and UIX capabilities.

 

The J2EE Development Environment

J2EE provides many advantages such as portability, scalability, the ability to interact with existing systems (via CORBA technology), security for internet applications and database access using EJBs, Application Development Framework Business Components (ADF BC), Web Services as well as the basic JDBC APIs.

In addition, a range of different technologies can be used to create enterprise systems in a J2EE environment:

·         Markup languages (HTML, XML)

·         Web page technologies (JSPs, UIX)

·         Frameworks (Struts)

·         Java Components (EJBs, Servlets)

·         Client Server Technologies (Swing, JClient)

 

J2EE is one of a few competing standards for web development, and arguably the one with the greatest user base, flexibility and depth. By using a unified standard and reusable, platform-independent components, systems built in this environment will have the benefit of a stable technology that is still improving. However, all of this flexibility requires a number of different skill sets. In order to build web based systems to work with Oracle databases using JDeveloper, some knowledge is required of a number of programming languages including:

·         Java

·         HTML

·         XML

 

In addition, developers need to know how to build web pages either using JSPs, UIX, or even straight HTML.  Struts is a useful framework that should at least be considered for all web development. To connect to the database, some kind of business services must be used, such as TopLink, ADF BC, or custom created Enterprise JavaBeans. In addition to Struts and UIX (discussed below), deploying enterprise systems using JDeveloper may also require an understanding of Web Services, application servers and the security models necessary for doing business over the Internet.

The result of all this complexity is that the development team has a daunting task ahead of them.

 

JDeveloper J2EE Compliance

The current vision for JDeveloper is influenced by the J2EE and broader Java development communities, which strive to make JDeveloper a fully featured J2EE development product. Building J2EE applications remains a challenging task with a steep learning curve. In this area, Oracle has taken advantage of its past experience with products such as Oracle Forms Developer to provide a graphical or metadata-based application development user interface, which helps to improve the efficiency of Java and web developers. JDeveloper 10g has made it easier to make the transition from tools such as Oracle Forms Developer or Delphi into the J2EE space.

However, JDeveloper remains inherently a 3GL environment.  The developer can never lose sight of the fact that the wizards are code generators.  There is no repository behind JDeveloper applications.

 

The Application Development Framework (ADF)

The JDeveloper 10g release introduces the Oracle Application Development Framework (ADF), which is based on the Model-View-Controller (MVC) architecture. ADF applications should be able to be deployed on any J2EE server and connect to any SQL database (although the author does not have experience working with JDeveloper outside of the Oracle environment).

ADF BC wizards help developers build applications that interact with a relational database. This allows application developers to focus on the business domain rather than on the underlying technologies. Even developers who have limited experience with the J2EE environment can be productive fairly quickly. Visual editors, diagrammers, property inspectors and component palettes have been incorporated into JDeveloper to help create simple applications as well as support and manage larger and more complex ones. Users can select default templates with more structure to get started quickly or more advanced J2EE users can choose a more do-it-yourself approach, and create their own templates and reusable components.

JDeveloper uses the Application Development Framework Business Components (ADF BC) technology as the primary way of handling database DML operations (queries, inserts, updates, and deletes). Before the 9i release of JDeveloper and the BC4J technology, connecting a Java-based application to the database was an extraordinarily difficult task. You needed to write complex Java Database Connectivity (JDBC) and/or SQL embedded in Java (SQLJ) code in order to coordinate a Java front-end with the database. In addition, you had to maintain your own data caching, batch your own updates, and keep track of table locks and commits. This complex interface with the database has proven to be one of the biggest hurdles to building web-based applications. Organizations that attempted application projects without a product such as JDeveloper were frequently over budget and found their applications difficult to maintain. In contrast, the BC4J components in JDeveloper provide a functional interface to the database that can be constructed using the built-in code generators or wizards.

The Oracle JDeveloper 10g release provides a visual design environment for modeling, testing, debugging and deploying J2EE applications. The ADF and associated code generators give JDeveloper a significant advantage over other Java development tools. ADF and ADF Business Components set JDeveloper apart as the tool of choice for Oracle developers building Java or web-based applications.

The 10g release deserves high marks for supporting the J2EE/Java development vision. Building J2EE applications remains a challenging task with a steep learning curve. JDeveloper 10g has made it easier for development organizations to make the transition from 4GL tools such as Oracle Forms Developer or Delphi into the J2EE space.

 

Struts

Struts is a framework that focuses on the controller portion of your application.  This means that it will handle the logic between pages.  It will control which page gets called next and what happens when it is called.  It will also act as a location for data validation (even though such logic is perhaps better placed in ADF BC).  Finally, Struts provides a clean way to handle internationalizations of your web pages.

Struts was developed as part of the Apache Jakarta Project, sponsored by the Apache Software Foundation. Struts uses a configuration file to initialize its own resources. Books about Struts include topics such as ActionForms, ActionMappings, and ActionForwards.

The Struts framework is based on Java Servlets, JavaBeans, ResourceBundles, and XML. Struts-based applications extend the classic Model-View-Controller (MVC) design paradigm (Model 2).

Struts offers many benefits to the web application developer, including the Model-View-Controller (MVC) design patterns in web applications. The MVC paradigm applied to web applications lets you separate display code (HTML and tag libraries) from flow control logic (action classes) from the data model to be displayed and updated by the application.

In traditional web development, you open a page on the screen, then click on a link that sends an http request to an application server.  Next, the server, (using some magic) prepares another page and sends it to you.  In the Struts environment, the process is quite different.  In Struts, your link is actually a request for a Struts action.  This action can do a number of things.  A simple action to “browse data” obtains the data from the business service and then forwards you to a page where the data will be displayed.   A more complex action might retrieve the data, modify it, and then forward you to one of several pages depending upon some condition.

 

Struts in JDeveloper

Oracle has extended the basic theory of Struts to facilitate the way in which ADF builds applications. Therefore, it may be difficult to try to map what you read about Struts to what JDeveloper generates. JDeveloper 10g has done a very nice job of removing much of the complexity from the environment. You will still need to understand the conceptual basics of Struts, but you will not need to be concerned with many of the lower level details of the technology.

JDeveloper 10g support for Struts-based J2EE application development includes the following features:

 

·         Struts Custom Tag Libraries - libraries that can be used to create UIX or JSP pages used in web applications

·         Struts Page Flow Modeler - interface to create application page flow, select web pages for editing, and run the application. You can drag icons selected from the Component Palette onto the page flow diagram of your application's web pages. This includes the Actions and ActionForwards. The diagram elements are automatically updated by the Modeler in the struts-config.xml file. The Structure window and Property Inspector let you edit the attributes of any Struts element.

·         Struts Configuration Editor - interface to edit the struts-config.xml file contained in the project’s WEB-INF folder. This file contains information about the names of application actions, action classes and form beans. This was the primary user friendly (non-code) interface in previous versions of JDeveloper.  It is unclear what use of this feature has since the inclusion of the graphical page flow modeler.

 

The graphical Struts designers and editors in JDeveloper 10g are solid efforts that continue to mature quickly.  However, Struts support in JDeveloper is still not entirely stable.  The tutorials and white papers available on OTN for Struts have not yet been updated.  If you attempt to work through these tutorials, you may have some trouble.  Papers written after February, 2004 have been updated. As of this writing there are still changes being made by the product development team so information included here may change a bit by the time the 10g version is in production. 

 

Building a Simple Master-Detail Application Using Struts

This section describes how to create a standard master-detail application with updating using Struts. This is the same common Dept/Emp master-detail application used in many previous examples. The only difference in the interaction with the application is that there are separate screens for doing the following:

1.       Browsing the Depts and Emps,

2.       Editing a particular Dept,

3.       and editing a particular Emp, 

 

Prior to the availability of JDeveloper 10g, building this in Struts required in-depth knowledge of Struts using mostly hand coding. In JDeveloper 10g, you work in a user friendly graphical environment. The Struts page to support the application looks like Figure 1:

 

Figure 1: Struts flow for a simple master-detail application

 

To build any application, first create the business services so that the ADF BC (or whatever service you are using) has been tested prior to working with the Controller/View piece of your application.

 

The flow starts with the /browsedeptDA Data Action using a drag and drop interface. Using the same drag and drop interface, the /browseDept Data Page is added and connected using a forward action.  This is all accomplished as in any computer drawing tool.  The wizards will have already written some code but nothing can be run at this point.

The next step in the process is to double-click the /browseDept Data Page to view the options for which technology to use (JSP, UIX, HTML).  After making a selection, a familiar looking blank page is created.  Data elements can then be selected which will not only populate the page, but also make modifications to the Data Action in order to make connections to the database.

 

After editing your screen, you will have a page that looks something Figure 2.

 

  Figure 2: Browse Data Edit Window

 

The rest of the diagram is built using much of the same kind of activity.  You draw the components and then edit the pages.  There is one major exception to this.  Sometimes the Data Actions require some complex logic.  For example, notice how there are two lines (Forwards) leaving the /editEmpDA Data Action in Figure 1.  This handles the situation when data that is entered has errors, so that the user will be sent back to the edit screen to re-edit the data.

This process is accomplished using a class that is associated with the DataAction. Double-clicking Data Action creates the Java class that can be edited.  In this case, the following code would be added to the class.

if (this.hasErrors(actionContext))

      {

System.out.println("EditEmpDAAction - success called - xfer to /editEmpDP.do ie. the jsp");     

        actionContext.setActionForward(actionContext.getActionMapping().findForward("success"));

      }

      else

      {

        actionContext.setActionForward(actionContext.getActionMapping().findForward("browse"));

      }

    }

 

This is actually a good way to manage very complex logic in an application.  Anyone familiar with production application web development will appreciate the clarity of this approach.

 

UIX

User Interface XML (UIX) is a set of technologies to support the building of web applications. It provides the functionality for managing events and the state of the application flow. It is designed for page-based navigation, rather than full-featured applications.

UIX uses the Model-View-Controller (MVC) design pattern in a J2EE framework and is based on Java technology. It can be used to create web applications. However, it is not necessary to have Java on the client side in order to use UIX. UIX can support different clients and includes APIs and Java class libraries.

The user interface components are used to build the View portion of a web application. The Controller manages the navigation between pages.

There are many advantages to using UIX technology. It is well integrated with J2EE and XML standards as well as Struts applications. UIX provides an open framework that is platform independent. It also often provides better performance than JSPs, requiring only partial screen refreshes and usually results in a nicer look with less effort required. Applications maintain a consistent appearance and can be customized at multiple levels.

UIX provides a significant improvement in development environments over JSPs or straight HTML.  One of the things that makes UIX tags nicer to work with is the idea of “events”. In a UIX button, for example, you can simply name an event such as “edit Emp” and pass that back to the framework as the button action.  In JSPs, all you can do is “submit” and the http request must be much more complex.

 

UIX in JDeveloper

Oracle’s Application Development Framework (ADF) includes ADF UIX for building J2EE component-based web applications built using XML.  ADF UIX is one of the view technology options with an open framework for building component-based J2EE- web applications.

ADF User Interface XML (UIX) pages are based on XML technology. The UIX tag library is somewhat easier to work with and delivers slightly better performance than JSP tag libraries. For example, UIX tags only require a portion of the screen to be refreshed when only a portion of the screen is changed, resulting in significant performance gains over JSP pages, where the whole screen is typically refreshed.

ADF UIX development is one of the areas where the JDeveloper 10g release has made great improvements. Developers can build JSPs or ADF UIX pages with virtually the same user-friendly interface. It provides the architecture for defining and customizing style sheets suitable for different user environment locations, browsers and platforms. Cascading Style Sheets (CSS) and server-side APIs for managing style information can help create attractive applications quickly and easily.

The wizards in JDeveloper also tend to be more sophisticated with UIX than they are for JSPs.  For example, a full set of UIX tags is available to build the entire master-detail browse screen with a single drag-and-drop operation.  Since JDeveloper has actually built dozens of UIX tags for you, it is possible to edit the screen as much as you desire.  For those familiar with Oracle Forms Developer, similar capability existed with the data block wizards.

ADF UIX is a technology for developing web applications with an XML component model in the presentation tier. It includes Java class libraries, APIs, and parsers for creating web applications with page-based navigation, such as an online shopping application.  ADF UIX supports a variety of clients, including HTML-compliant browsers and mobile devices.

You can use ADF UIX to develop the entire application or different aspects of an application based on the Model-View-Controller Model 2 design pattern. ADF UIX includes a large group of user interface components, used to help build the user application View layer.

JDeveloper includes an XML editor that can be used to create UIX pages, which can be customized for various environments. uiXML is used to create the UIX pages and the navigation between them without the need to write a large amount of Java code. The UIX UI components included with JDeveloper can also help maintain a consistent look and feel. Figure 3 shows the UIX Visual Editor. Items from the Component Palette can be easily dragged and dropped onto the editor.

 

 

 

Figure 2: JDeveloper UIX Visual Editor

Conclusions

JDeveloper 10g’s motto “Productivity with Choice”, although reflective of the tremendous flexibility of the tool sidesteps the additional complexity that has made traditional Oracle developers reluctant to embrace J2EE. The popularity of less flexible alternatives such as PL/SQL Server Pages, Portal, and HTML DB demonstrates that, in addition to flexibility, developers also require guidance for systems development best practices.

The introduction of the Application Development Framework (ADF) represents a significant rethinking of the development environment. What is still lacking is advice for development best practices and a clear Software Development Life Cycle (SDLC) for building J2EE systems. To be fair, the entire industry is still waiting for a coherent SDLC to emerge for building J2EE systems based on solid relational databases back-ends.

For the short term, the J2EE development environment will continue to mature and new features will be added. For example, JavaServer Faces (JSFs) are the latest addition. JDeveloper will clearly be supporting JSF in the near future. The UML modeling area will also evolve rapidly towards database modeling and design so that JDeveloper will match and ultimately surpass Designer and perhaps products such as Toad. The activity, class and use case modelers will also allow JDeveloper to more easily support complex process-based application development. Already, JDeveloper 10g has paid attention to team-based development integrated with Oracle SCM and products such as CVS. Although some of these capabilities are included in the current release, additional usability improvements will take place in the near future.

The expected long-range vision is that JDeveloper will move closer and closer to being a unified design and development environment and an ever more user-friendly tool. JDeveloper 10g is continually evolving, offering substantive support for the J2EE architecture and helping to build systems that are capable of responding very well to changes in that architecture as they occur.

 

Useful References

The following are some useful references for the topics discussed in this paper.:

·         Oracle 9i JDeveloper Handbook, Koletzke, Dorsey & Faderman, (Oracle Press, 2002)               ISBN: 0072223847

·         Oracle 9iAS: Building J2EE Applications, Morrisseau-Leroy (Oracle Press, 2002)                ISBN: 0072226145

·         Oracle 9i Application Server Portal Handbook, Vandivier & Cox (Oracle Press, 2001)                ISBN: 0072222492

·         Oracle 9i JDBC Programming, Jason Price, (Oracle Press, 2002) ISBN: 0072222549 (not needed if you use BC4J)

·         Java2: The Complete Reference (5th Edition), Herbert Schildt, (McGraw-Hill, 2002)             ISBN: 0072224207

·         Struts Kick Start, Turner & Bedell, (SAMS, 2002) ISBN: 0672324725

·         Oracle9i XML Handbook, Chang, Scardina & Kiritzov, (Oracle Press, 2001) ISBN: 007213495X

·         Refactoring: Improving the Design of Existing Code, Martin Fowler (Addison-Wesley, 1999)        ISBN: 0201485672

·         Oracle 9i Web Development, Bradley D. Brown (Oracle Press, 2001) ISBN: 0072193883

·         The Java Class Libraries – Volumes 1, 2, 3, Chan & Lee, (Addison-Wesley)

·         The Java Tutorial (series), Campione, et. al (Addison-Wesley)

·         Oracle JDeveloper 10g: Empowering J2EE Development, (APress, 2004) ISBN: 1590591429

 

About the Author

Dr. Paul Dorsey is the founder and president of Dulcian, Inc. an Oracle consulting firm specializing in business rules and web based application development. He is the chief architect of Dulcian's Business Rules Information Manager (BRIM®) tool. Paul is the co-author of seven Oracle Press books on Designer, Database Design, Developer, and JDeveloper, which have been translated into nine languages.  He is on the Board of Directors of ODTUG, President of the New York Oracle Users Group and a Contributing Editor of IOUG's SELECT Journal.  In 2003, Dr. Dorsey was honored by ODTUG as volunteer of the year, in 2001 by IOUG as volunteer of the year and by Oracle as one of the six initial honorary Oracle 9i Certified Masters.  Paul is also the founder and Chairperson of the ODTUG Business Rules Symposium, now in its fifth year.