Avoiding Landmines as You “Struts Your Stuff” Through J2EE Development Using JDeveloper

 

Overview

This is a very confusing time in the IT industry. There is more and more competition in the database arena. On the database side of the world, there is a constant flood of new features in recent releases that most developers and DBAs are unaware of. On the software development side, Extreme Programming (XP) and Agile methods have taken the object-oriented (OO) world by storm but are inconsistently adopted in the OO community and largely unheard of in the database community. There are excellent J2EE tools and mechanisms for connecting Java to the database but the development community at large is uncertain about how to embrace this new technology.

The application development environment is becoming increasingly complex with more languages to learn, more products to become familiar with and a larger technology stack (J2EE) to understand. Add to this the object-oriented (OO) concepts of use cases, scenarios, analysis-level class and activity diagrams, Oracle’s Business Components for Java (now part of the Application Development Framework - ADF), and struts architecture and the learning curve for building J2EE-compliant systems becomes very steep.  This paper will attempt to provide some helpful guidelines for developers trying to make sense of all of this new technology when building systems with JDeveloper.

J2EE Web Development

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 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, 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.

J2EE and JDeveloper 10g

The J2EE Model-View-Controller (MVC) architecture used in JDeveloper is as follows:

·         Model How the component accesses data

·         View The component's look-and-feel

·         Controller The component's response to events

The client data model is an implementation of the MVC Model layer. Most Swing components are visual in nature, which provides the View layer. The event code you write for each component corresponds to the Controller layer.

It is simple to use Swing components in JDeveloper. Objects can be added in three ways. They can be placed into the Structure window in a tree structure, dropped directly into the Visual Editor, or added in the code. Getting the components on the screen and coupling them to ADF BC is very straightforward. With practice, you can quickly be as productive at adding components as in any 4GL tool such as Oracle Forms Developer.

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. Still, 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.

Oracle Extensions and the Application Development Framework (ADF)

The introduction of the Application Development Framework in JDeveloper 10g represents a significant rethinking of the development environment. JDeveloper will move closer and closer to being a unified design and development environment. The 10g release represents significant improvement over 9i because of the following:

·         Introduction of the Application Development Framework

·         Expanded 4GL development support for Struts, JSP code, and ADF UIX pages, including drag-and-drop data binding to connect Java client and web client view layers with business services layers such as ADF BC and Enterprise JavaBeans (EJB)

As with all popular Java development tools, JDeveloper 10g is clearly evolving, making it an ever more user-friendly tool that offers substantive support for the J2EE architecture and is responding very well to changes in that architecture as they occur.

The Application Development Framework is one area of JDeveloper that is very important but will not be obvious to most users. The benefits of ADF are evident when creating complex production applications. Even then, in order to truly appreciate ADF, you will need to have built other J2EE-compliant applications without it.

When building applications, there are numerous places where the framework will automatically take advantage of components in ADF. This greatly decreases the amount of coding required. Other benefits of ADF are evident when modifications to the applications are required. Traditionally built J2EE applications are notoriously difficult to modify. Things that should be simple such as adding an attribute to a table that then must be maintained in the applications can require hours, if not days, of effort without ADF. It is still not trivial to make these modifications using ADF, but it is much easier than the alternative.

Application Development Framework Business Components (ADF BC)

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 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 attempt application projects without a product such as JDeveloper are frequently over budget and find their applications difficult to maintain. In contrast, the ADF BC 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.

Struts

Struts is a framework that supports the page flow logic behind building web applications. It was developed by The Apache Software Foundation (jakarta.apache.org/struts/). Struts technology was created to bring order to the chaos of applying complex logic to the process of building and managing entire web applications including Java program files and the UI (JSP, UIX, and HTML) files.

Struts is now a popular framework for managing web application development. Despite its popularity, it has a very steep learning curve. Struts is one area where JDeveloper 10g has done an extraordinary job of making development much easier. The JDeveloper support of Struts through ADF greatly reduces the level of effort required to build a Struts-based application. Nowhere is the power of ADF more evident than in building Struts-based web applications.

Working with Struts still requires a great deal of skill. A thorough understanding of the Struts framework as well as Oracle's implementation of Struts is required to successfully build Struts-based applications in JDeveloper. However, once you understand the framework, using JDeveloper to build web applications is almost as rapid as the productivity that can be achieved in a 4GL. As an added benefit, the code generated is consistent and largely self-documented by JDeveloper's graphical diagramming tool, which creates page flow diagrams.

Although Struts can be used to manage any J2EE (or Java) development effort, its primary use is for web development. This includes applications built using JSP pages, HTML, and Oracle's ADF UIX framework. Struts is used for building and managing page flow. Struts logic will manage how pages are connected, what happens before the page is called, and what happens when you submit the page. In addition, with ADF, the Struts controller manages the communication of data from the Model layer to the View layer.

As with all frameworks, Struts provides both architecture and a library of elements to support that architecture. Struts includes a number of tag libraries that are designed to simplify the interaction between your page elements and Struts controller functionality.

JDeveloper 10g has decreased the complexity of building applications using Struts. However, using Struts for the Controller in J2EE development is not as easy or straightforward as the marketing hype would have you believe. Furthermore, Oracle has extended the Struts environment. Although this makes working with Struts in JDeveloper somewhat easier, it has the unfortunate side effect of making it more difficult to learn about Struts by using other sources of information. In particular, there are many places where, in order to take advantage of the Application Development Framework (ADF) and the associated generators, it is necessary to carefully follow somewhat obscure naming conventions and it is helpful to perform tasks in a particular order.

 

Implementation of Struts in JDeveloper 10g

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.  The JDeveloper Struts Page Flow Component Palette is shown in Figure 1.

 

 

Figure 1: JDeveloper Struts Page Flow Component Palette

 

JDeveloper has done much more than provide a graphical user interface to write Struts code. ADF has extended and simplified the framework to assist developers in building Struts applications. In Oracle 9i JDeveloper, developers learned how to work with Struts like any J2EE developer. It was necessary to write much of your own code and it was often difficult to get things working properly. Moving to 10g, development became much easier, but also very different. JDeveloper 10g extends the base Struts functionality and binds it closely to Oracle ADF.

Assuming that you use ADF business services, you will have little need to worry about Struts while you are building your ADF BC project. The Struts components are automatically configured to interact with the business services you are creating. Your Struts development really begins after you build the business services project. JDeveloper 10g has extended many traditional Struts elements to give you the ability to develop code faster and make it more maintainable.

In traditional Struts development, you build pages, action classes, and ActionForm classes using the code editor of your choice. In JDeveloper 10g Struts development, you will use a visual page-flow editor to define pages, data actions, and forwards using a drag-and-drop interface.  A sample page flow diagram is shown in Figure 2.

 

Figure 2: Struts Page Flow Diagram

Most of the code is generated for you; however, you can modify the source code at any time by switching to the source code tab located at the bottom of the screen. This approach lets you concentrate on the page flow logic while JDeveloper handles the drudgery of coding the struts-config.xml file.

As you build Struts applications, control passes to pages or data actions in a way similar to that of a state transition engine. This is an excellent way to think about development, and JDeveloper implements this philosophy brilliantly.

Objects can be added in three ways. They can be placed into the Structure window in a tree structure, dropped directly into the Visual Editor, or added in the code. Figure 3 shows the main development areas in JDeveloper.

 

 

 

 

 

 

 

 

Figure 3: JDeveloper main work areas

 

Getting the components on the screen and coupling them to ADF BC is very straightforward. With practice, you can quickly be as productive at adding components as in any 4GL tool such as Oracle Forms Developer.

Do’s, Don’ts and Warnings

Trying to control the objects you have created reveals both the blessing and the curse of using Java. Java is almost limitlessly flexible. You can do just about anything you want; however, almost anything you might want to do other than dropping a Swing component into your application and setting properties in the Property Inspector requires a good deal of work to figure out how to achieve the desired result.

Even a simple-sounding task such as making a field wider, adding a double-click event, or changing the color of a field in a specific context may be a frustrating experience if you do not have some guidance. Using the right layout manager may help. It may take you a few tries until you find the right clue in the right Java book or find the answer to your question on an Internet list serve to solve some of the problems you may encounter.

Development Strategy

Conventional wisdom in the J2EE community recommends placing as little as possible into the database and using it as a persistent copy of the Java classes. Using this approach, all business rule enforcement resides in the middle and client tiers. All page flow logic is coded in Struts and all specific UI control is coded in a client JSP using JavaScript.

Using this approach has not been successful in our experience. By moving the business logic out of the database, terrible performance problems were encountered that were virtually impossible to correct. The only solution was to move more and more business logic into the database. Eventually the conventional wisdom was rejected in favor of the following development strategy:

1.        Place as much business logic as possible in the database. For every user interface screen, build a view in the database specifically for that screen. These views are often based upon multiple tables so that handling Insert/Update/Delete logic is supported through INSTEAD OF triggers defined on those views.

2.        When logic is used to update either data in the database or information in the user interface, the algorithms are contained as stored procedures in the database.

3.        Struts Page Flow logic can be quickly built by hand in JDeveloper 10g.

4.        User interface (view layer) logic is minimized as reloading a light JSP page without a lot of JavaScript can be done very quickly.

 

Using these guidelines in your J2EE development strategy not only provides for a solid and effective way of building applications, but also moves code out of the part of the system that is most likely to change. The J2EE environment is still rapidly evolving. Last year, JSPs and JavaScript were the structures of choice. This year, JSPs and Struts were favored with little JavaScript. Next year, JavaSever Faces (JSFs) are likely to be the preferred development structure. If most of your system is in the relatively non-volatile database environment (assuming remaining in an Oracle database), moving the logic out of the J2EE environment will increase the lifespan of the applications being built.

 

Extreme Programming (XP) and Agile Techniques

It is beyond the scope of this paper to describe these areas in detail. However, adopting some of the XP/Agile techniques can significantly enhance the development environment. The discipline of being on a rapid (2-4) week delivery cycle helps improve the quality of the work done by development teams. The concept of pair programming where two individuals team up to more efficiently execute a task is a very easy way to improve developer productivity.

Hardware Recommendations

The Java development environment has increased the need for sophisticated workstations in comparison to what was used for client/server development. The following recommendations may be more expensive but the increased productivity for the developers is well worth the added cost.

In order to develop effectively in this environment, the following are highly recommended:

·         Dual 20”monitors

·         >=1 GB memory (even if you are not running the DB) 2 GB is nice; 4 GB is ideal.

·         > 2 GHz processor

Trying to develop with small monitors and slow machines will be a very frustrating experience.

 

Warnings

The following warnings are based upon our actual experiences building applications with JDeveloper 10g.

1.        Cut and paste code with caution. Use the JDeveloper wizards whenever possible to avoid mistyping or code errors. Most data operations are in two places XML, Code (Java, HTML) so deleting manually should be avoided. It is often difficult to find all of the places where code is stored.

2.        Don’t rename items. You may get unpredictable results. JDeveloper is really a 3GL code generator. When you use the wizards, you are adding code in several places at the same time. If you rename items, the JDeveloper wizards may not correctly update all of the places where those names are used. Ensuring that this is done correctly is a very difficult task. Even though JDeveloper has improved in its capability to do this, renaming is still not a completely foolproof operation. You should be very careful about renaming things, particularly business components because so many application elements are dependent upon them.

3.        Deleting elements does not always delete everything. For example, dragging and dropping an element onto a JSP page, the element will be created and so will the binding in the XML file. If you delete the element from the JSP page, the XML file will not be automatically updated. The JDeveloper wizards will help increase productivity but developers still need to understand what is happening behind the scenes.

4.        Save often (certainly prior to each running). JDeveloper 10g is a very stable product (more so than any of the past releases). However, the program may occasionally hang, particularly when working with large, complex programs on underpowered machines.

5.       Make backups of the whole directory structure. A JDeveloper application is not like an Oracle Forms application that is completely contained within no more than a handful of files. Java applications can often include hundreds of files spread across a dozen or more directories. When developing applications, if a program becomes corrupted or you decide to change something, how can you return to a stable version? In Forms, this was a simple matter of versioning the application several times each day. With JDeveloper, the only way to save a version is to go to the root directory of the application and copy the entire directory structure. This should be done no less than daily.

 

Conclusions

In some respects, we are now in the worst of all possible worlds. The technology available includes UML tools, the J2EE stack, and relational databases. A typical development shop will create use cases, class diagrams and sequence diagrams. Then they will try to use a J2EE development IDE and start coding with no clear idea about how to translate these diagrams to the relational database. Even with the state of the art technology stack, no systems that we are aware of have been built to date that have done this job well.  What should be happening?

·         Design databases to be more OO friendly

·         Deliver some class representation to the OO programmer (database views, EJBs, proprietary middle tier objects such as Oracle ADF BC entity objects) to bridge the gap between the database and the OO applications.

We are now working in a very volatile software development environment. The current web environment is overly complex. The J2EE stack is still evolving. Java Server Faces (JSFs) and Struts are emerging as promising new technologies. However, since the technology is evolving so fast, many of the development resources devoted to any of these technology stacks may be wasted since applications may look drastically different next year. Struts provides an excellent architecture for managing web application logic. Even though this architecture is quite powerful, it is neither particularly intuitive, nor easy to learn. JDeveloper 10g has greatly simplified the process of incorporating Struts into your application development environment.

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 Resources and References

In addition to OTN white papers, you can do an Internet search using Google for help (it will even find the OTN papers).

Posting questions on ODTUG, OTN is also a good way to get help with your projects. However, the best advice is to get a mentor. Without one, you will fail one or more projects. Basic Struts books may not help much; however, the following are some useful references for the topics discussed in this paper:

·         Oracle JDeveloper 10g Handbook, Faderman, Koletzke & Dorsey, (Oracle Press, 2004) ISBN:0072255838

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

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

·         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 sixth year.