Developer Tools
JDeveloper
An Oracle JDeveloper How To Document
Duncan Mills
January 2004
Introduction
JDeveloper 10g and Multiple Configurations
Creating a new Multiple Configuration Workspace
Creating a Working Multiple Configuration Workspace from an Existing WAR file
Running Child Application Page flows
Conclusion
This document discusses how you can set up a JDeveloper 10 g workspace in order to use the multiple configuration features of Apache Struts. The use of multiple configuration files for the same application is a new feature added to Struts version 1.1 to help application developers better structure their sites and to ease the burden of maintenance for large applications. Multi configuration actually encompasses two different styles of usage:
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml, /WEB-INF/struts-config-registration.xml</param-value>
</init-param>
...
</servlet>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>
config</param-name>
<param-value>
/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>
config/child1</param-name>
<param-value>
/WEB-INF/child1-config.xml</param-value>
</init-param>
<init-param>
<param-name>
config/child2</param-name>
<param-value>
/WEB-INF/child2-config.xml</param-value>
</init-param>
...
</servlet>
This document assumes that you are already familiar with the basic use of Struts, Struts multiconfig usage and of JDeveloper 10g as a Struts development environment.
JDeveloper 10 g and Multiple Configurations
The reason for producing this document is to help developers around a restriction in the initial release of the JDeveloper 10 g product. With this release of the product only one Struts page flow diagram can exist in each project. Attempting to use multiple page flow diagrams within a project can lead to unpredictable results and diagram corruption. As a result, applications which want to utilize peer or sub configurations will need to be organized in a special way to allow full page flow diagram functionality for each configuration file. The exact steps are outlined below, both for new applications and existing applications.
Creating a new Multiple Configuration Workspace
When creating a new multi config application you will need to plan in advance how many configuration files you will be using. In this example we'll use a total of three configurations, struts-config.xml as the parent configuration and two sub applications child1-config.xml and child2-config.xml. The principals of maintaining this projects in sync revolve around the use of a common HTML root and a common J2EE application name shared by all the projects. So lets step through the creation process for our workspace.
<?xml version = '1.0' encoding = 'windows-1252'?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<description>Empty web.xml file for Web Application</description>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>
config</param-name>
<param-value>
/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>
config/child1</param-name>
<param-value>
/WEB-INF/child1-config.xml</param-value>
</init-param>
<init-param>
<param-name>
config/child2</param-name>
<param-value>
/WEB-INF/child2-config.xml</param-value>
</init-param>
...
Creating a Working Multiple Configuration Workspace from an Existing WAR file
If you have an existing code base or application which uses multiple configurations which you want to edit through JDeveloper you can import a WAR file of the application into an empty JDeveloper Workspace using the following steps :
<!-- Action Servlet Configuration -->
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml, /WEB-INF/struts-config-registration.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
Once you have completed this process for each sub configuration you will be able to open a page flow diagram up in each project. You may choose to move JSP files etc to the relevant project that they apply to, however, there is no need to specifically do this as JDeveloper will work out where the files are if you try and drill down into them from the page flow diagram.
Running Child Application Page Flows
In the situation where you have sub-applications (such as in our example child1 and child2), you will be able to run Actions on the parent page flow diagram, or any peer application of the parent directly. However, if you attempt to run an Action from a sub application page flow diagram, it will fail with HTTP 400 (page cannot be found) error. This is because the URL that the runner will construct for the Action will not include the sub application path. For instance the url: http://localhost:8988/multiApp-context-root/child1_index.do may be generated rather than the correct http://localhost:8988/multiApp-context-root /child1 /child1_index.do.
There are several approaches you can take to making it possible to run from a child application diagram. Take the situation where the parent project has a single entry point that the user always has to traverse, for instance a logon page. In this case using the context menu on the parent diagram set that page as the default run target for the parent diagram. This has the side effect of setting the Action unknown attribute to true for that action, so if you run from any of the other diagrams where an invalid Action URL is generated, Struts will redirect you to the application start point automatically.
Note that this will only work successfully if your Action names are unique across all of the sub applications.
However, you may wish to unit test just the flow within a particular sub application. If this is the case then you will need to adopt the following procedure.
Although the initial release of JDeveloper 10 g does not seamlessly support multiple configuration Struts applications, with a little care it is entirely possible to use the product with such applications. In the next version of JDeveloper 10 g it will be possible to dispense with the multiple project requirement, although structuring the workspace in this way may have benefits if multiple developers are working on different sections of the application.
drmills v1.1 13-Jan-2004