c j client and jsp applications in oracle9i jdeveloper · creating a default, but functional bc4j...

15
Reviewed by Oracle Certified Master Korea Community ( http://www.ocmkorea.com http://cafe.daum.net/oraclemanager ) CREATING JAVA CLIENT AND JSP APPLICATIONS IN ORACLE9I JDEVELOPER Toto, I have a feeling we’re not in Kansas anymore! We must be over the rainbow! —Dorothy, The Wizard of Oz, MGM (1939) Note: This paper is a companion to the other paper for this conference “J2EE for Oracle Technologists,” which is also available from the same location as this paper. The other paper provides more details about J2EE strategies. If we apply Dorothy’s observations to the world of Java development, truer words have not been spoken. We no longer only inhabit the familiar world of PL/SQL, where we understand and are in tune with the methods for developing and deploying applications. There are many promises over the rainbow, but to realize them, we need to become familiar with new development and deployment methods. Oracle9i JDeveloper offers a powerful interface for quick development of bug-free Java code. Since it is Oracle’s premier Java tool, you can use it to create all different styles of applications that the Java language supports. The challenges are in understanding the different types of applications and in knowing where to go in the tool to get started. This paper serves as an introduction to the main characteristics of two main deployment options that you can create using Java: Java client (Java application and applet) and JavaServer Pages (JSP) technology. The paper briefly introduces the architecture of each of these options separately, and discusses how to get started developing each alternative using the JDeveloper wizards. The first section of this paper combines the discussions of architectures and development methods for the Java application and applet styles as both of these styles fall into the category of a “Java client” application. The second section of the paper addresses the JSP architecture and development methods in JDeveloper. The JDeveloper online documentation (help system) contains demo applications and tutorials that supplement the introduction in this paper. This paper also provides some details about the steps that are required to create a production-ready application using the wizards. JDeveloper handles the deployment of Java code using deployment profiles and standard J2EE distribution files. The details of deployment are outside the scope of this paper but are also well explained in the JDeveloper documentation. Since all deployment options discussed in this paper use Oracle’s Business Components for Java framework, it is useful to start by briefly explaining this feature. Further explanation is outside of the paper’s scope but is, again, available in the JDeveloper help system and on the Oracle Technology Network web site (otn.oracle.com). Note At this writing, the current production version of Oracle9i JDeveloper is release 9.0.3. If your version is different, some options, menu selections and features may not appear as mentioned in this paper. BUSINESS COMPONENTS FOR JAVA Oracle’s Java database framework, called Business Components for Java (BC4J), offloads much responsibility from the application programmer. It provides a set of .class files that you can use to easily hook into database objects such as tables and

Upload: others

Post on 03-Aug-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: C J CLIENT AND JSP APPLICATIONS IN ORACLE9I JDEVELOPER · Creating a default, but functional BC4J layer in JDeveloper is easily accomplished by means of running the Business Components

Reviewed by Oracle Certified Master Korea Community

( http://www.ocmkorea.com http://cafe.daum.net/oraclemanager )

CCRREEAATTIINNGG JJAAVVAA CCLLIIEENNTT AANNDD JJSSPP AAPPPPLLIICCAATTIIOONNSS IINN OORRAACCLLEE99II JJDDEEVVEELLOOPPEERR

Toto, I have a feeling we’re not in Kansas anymore! We must be over the rainbow!

—Dorothy, The Wizard of Oz, MGM (1939)

Note: This paper is a companion to the other paper for this conference “J2EE for Oracle Technologists,” which is also available from the same location as this paper. The other paper provides more details about J2EE strategies.

If we apply Dorothy’s observations to the world of Java development, truer words have not been spoken. We no longer only inhabit the familiar world of PL/SQL, where we understand and are in tune with the methods for developing and deploying applications. There are many promises over the rainbow, but to realize them, we need to become familiar with new development and deployment methods.

Oracle9i JDeveloper offers a powerful interface for quick development of bug-free Java code. Since it is Oracle’s premier Java tool, you can use it to create all different styles of applications that the Java language supports. The challenges are in understanding the different types of applications and in knowing where to go in the tool to get started.

This paper serves as an introduction to the main characteristics of two main deployment options that you can create using Java: Java client (Java application and applet) and JavaServer Pages (JSP) technology. The paper briefly introduces the architecture of each of these options separately, and discusses how to get started developing each alternative using the JDeveloper wizards. The first section of this paper combines the discussions of architectures and development methods for the Java application and applet styles as both of these styles fall into the category of a “Java client” application. The second section of the paper addresses the JSP architecture and development methods in JDeveloper. The JDeveloper online documentation (help system) contains demo applications and tutorials that supplement the introduction in this paper.

This paper also provides some details about the steps that are required to create a production-ready application using the wizards. JDeveloper handles the deployment of Java code using deployment profiles and standard J2EE distribution files. The details of deployment are outside the scope of this paper but are also well explained in the JDeveloper documentation.

Since all deployment options discussed in this paper use Oracle’s Business Components for Java framework, it is useful to start by briefly explaining this feature. Further explanation is outside of the paper’s scope but is, again, available in the JDeveloper help system and on the Oracle Technology Network web site (otn.oracle.com).

Note

At this writing, the current production version of Oracle9i JDeveloper is release 9.0.3. If your version is different, some options, menu selections and features may not appear as mentioned in this paper.

BUSINESS COMPONENTS FOR JAVA Oracle’s Java database framework, called Business Components for Java (BC4J), offloads much responsibility from the application programmer. It provides a set of .class files that you can use to easily hook into database objects such as tables and

Page 2: C J CLIENT AND JSP APPLICATIONS IN ORACLE9I JDEVELOPER · Creating a default, but functional BC4J layer in JDeveloper is easily accomplished by means of running the Business Components

views. Without BC4J, you have to write low-level Java database connectivity (JDBC) code that connects your Java code to database objects. BC4J hides these low-level calls in a more abstract layer and allows you to concentrate on the application logic rather than the Java database access mechanics. BC4J also provides a non-database area for data validation, data caching, and session management. Creating a default, but functional BC4J layer in JDeveloper is easily accomplished by means of running the Business Components Package Wizard. JDeveloper also helps in creating a deployment package that contains the many .class files that this wizard creates. A single BC4J project can service many applications and is not specific to a particular deployment style.

COMMON DEVELOPMENT STEPS The steps that you use to create an application in JDeveloper are slightly different depending on the style of application that you are developing; however, there are some common steps as follows:

1. Create a workspace. The top level of file organization in JDeveloper is the workspace. It is really just a logical container for a number of project files that you are working on at the same time. Projects contain the actual program code files (such as .java, .html, and .xml) and are used for creating deployment packages. The workspace may include projects that are also used by other workspaces.

2. Define the BC4J project. This may be an existing BC4J project that you just include in the current workspace, but, if you want to use BC4J to connect to a database, there must be a BC4J project open in the workspace so that the data elements are available to the application projects. The BC4J project stores the objects that will allow your program to access the database. After defining this project, you add code and definitions that implement specific business rules.

3. Test the BC4J layer. You can use the internal Oracle Business Component Browser to test the BC4J objects and your additional code in the BC4J layer. This step is recommended so that you can verify that all code in this layer is correct before building the user interface code that uses this layer.

4. Create a project for the application. It is best to keep the BC4J files in a separate project (in case you want to have multiple projects access that layer) so you will also need to create the project for the application code.

5. Run other wizards as required. Use the New gallery (File | New) to add files to the project for the user interface. All wizards create a certain amount of code that you will need to modify to fit your specific application requirements.

6. Modify the generated code. You will need to work other application-specific features into the generated code or modify the default behavior by writing code. Depending on the wizard that you run, the effort you need to put into this will vary. Some wizards create very complete code, whereas others create an emptier shell that you have to fill in significantly.

7. Test and deploy the code. You need to perform unit tests of the code within the JDeveloper environment first. This allows you to use the native JDeveloper debugger to resolve problems. When the test and fix cycle is complete, you create a deployment package using the deployment profile wizards (available in the New gallery) and move this to the final test platform that more closely mirrors the actual runtime environment. For example, if you were creating an applet, you would package the required .class files and move them with the supporting libraries to a web server. This would allow you to test the deployment package as well as to check that the code works properly outside the JDeveloper environment. JDeveloper’s deployment utilities help greatly with the packaging and moving operations.

JAVA CLIENT APPLICATIONS As mentioned in the companion paper, the term “Java Client” refers to both Java application and applet styles of deployment. Java Client means that the JVM used to run an application is a process on the client machine—either in a browser session or as a standalone session. Although there are similarities in the development steps, there are architectural differences between the two styles, so this section will discuss their architectures separately.

JCLIENT The issue of connecting standard Java components to database objects is one that requires much thought and effort. The traditional solution is to write JDBC code that connects to the database and retrieves and updates values based upon settings in user interface objects such as text fields and checkboxes. Oracle has solved this using a technology called JClient. JClient sets up a code layer that performs the binding of Java user interface components (JavaBeans such as JTextField and JCheckBox)

Page 3: C J CLIENT AND JSP APPLICATIONS IN ORACLE9I JDEVELOPER · Creating a default, but functional BC4J layer in JDeveloper is easily accomplished by means of running the Business Components

to BC4J objects. This allows developers to easily bind the interface elements to data; for example, to connect a text field to a BC4J attribute (that represents a column in a table), the only thing required is a property setting on the text field’s property list.

The JClient technology is used with Java client applications such as Java applications and applets. It also appears in a modified form in JDeveloper’s BC4J Data Tags Library that you use to create JSP applications.

JAVA APPLICATION The term “Java application” refers to a particular style of Java code. In Java terms, the code is really just an “application,” but since that term is a common one in the IT world, it is more properly preceded by the word “Java.” A Java application runs on the client machine in a standalone Java Virtual Machine (JVM) runtime process as depicted in (1) in Figure 1. BC4J class files communicate with the database and the application (2).

Figure 1. Java application runtime

APPLETS Applets are an alternative that better leverages the strengths of web technology. A An applet is started from a web browser session on the client. When the applet is first run, the applet is copied from the application server to the client machine. In subsequent executions of the same version of the applet, a copy of the applet located on the client machine is run. Applets give you all of the functionality of a Java application as if you were deploying client/server, but allow you to maintain it over the Web. As with Java applications, you are working entirely in a Java environment and can use JDeveloper to create the code.

Development of an applet is similar to development of a Java application. The main development differences are the following:

• The applet requires an HTML link or HTML page to start it. An applet tag in the HTML source code signals to the browser that it must start a JVM session and run the applet code.

• The applet is subclassed from the JApplet (or Applet) class. Java applications are based on other classes such as JFrame.

• The applet runtime executes an init() method when the applet starts up. Java applications execute a main() method first.

Page 4: C J CLIENT AND JSP APPLICATIONS IN ORACLE9I JDEVELOPER · Creating a default, but functional BC4J layer in JDeveloper is easily accomplished by means of running the Business Components

As with Java applications, applets allow you to use the rich user interface components that are offered by AWT and Swing libraries. The applet differs from the Java application only in the way it is started (from a browser) and in the initial location of the code, which is an application web server.

CREATING JAVA CLIENT CODE IN JDEVELOPER The development process for creating Java applications and applets in JDeveloper is very similar because both use the same wizards to build with the same GUI controls. This paper assumes that you will leverage the power of the JDeveloper wizards to provide a starting point for your application.

Note

This paper is written with the production release of JDeveloper 9.0.3. The names and locations of various wizards may change over time. If you cannot find a particular utility or wizard as named in this paper, skim through the appropriate nodes in the New gallery (File | New) for the closest match.

JCLIENT FORM WIZARD The main wizard that you use to create a JClient application using the BC4J framework is the JClient Form Wizard. You can access this wizard by selecting File | New to display the New gallery, then opening the Client Tier\Swing/JClient for BC4J category and double clicking Form. The wizard’s first page allows you to select a “frame” (for a Java application) or “applet” (for an applet). You may then specify a single-table or a master-detail layout.

Note

The JClient Form Wizard was called “Business Components Data Form Wizard” in JDeveloper 3.x.

This method assumes that you have created a connection object that specifies the proper schema and database attributes. You also must create or open a BC4J project that contains the database objects required for the application. Another assumption is that you have written business rules as much as possible into the BC4J layer and do not have to supplement that layer much after creating the user interface.

BC4J CLIENT DATA MODEL DEFINITION WIZARD Before starting the wizard, there is an additional step required for creating a client data model. A client data model (or data definition) is a declaration of the view objects that you will be using from a particular BC4J application module. The client data model is stored in an XML file (with a .cpx extension) in the application project.

This is an additional layer (not required in JDeveloper 3.x) that allows your application module to conserve resources by instantiating only the view objects that are needed for the Java client application instead of all the view objects that are defined for the BC4J application module.

The client BC4J Client Data Model Definition Wizard may be started from the New gallery’s Swing/JClient for BC4J category. It is also available by clicking the New button when declaring a data model in the JClient Form Wizard.

APPLICATION PROJECT WIZARD For Java applications, you can add a project with an empty application class and (optionally) a frame class by using the New gallery’s Project Containing a New Application item. The wizard will step through the creation of a project and then launch the Application dialog and (optionally) the Frame dialog. You will end up with a blank frame which you can use to lay out objects using the UI Editor and Code Editor. You can also add objects to the frame using several panel wizards.

Page 5: C J CLIENT AND JSP APPLICATIONS IN ORACLE9I JDEVELOPER · Creating a default, but functional BC4J layer in JDeveloper is easily accomplished by means of running the Business Components

APPLET WIZARD The JClient Form Wizard described before allows you to select either a frame application (Java application) or applet. Either option will connect to a BC4J layer. You can also select Applet from the Swing/AWT category in the New gallery to start the New Applet dialog. This dialog provides a blank applet file into which you can layout objects but there is no automatic connection to BC4J objects. The Applet HTML Page item in the same category of the New gallery allows you to create an HTML file that can be used to call the applet.

PANEL WIZARD The way to attach BC4J to a Java application or applet is by creating a panel that references the JClient binding code. The Panel Wizard helps you create a first-cut panel containing data elements that represent a view object in your BC4J project. Select File | New and select Panel from the Client Tier\Swing/JClient for BC4J category. There is also an Empty Panel Wizard available in this category that is associated with a client data model, but you need to add data elements manually.

Tip

Selecting New from the right-click menu on a project node will open the New gallery faster than selecting from the main menu.

DATA BINDING Panels are bound to the data model using a line of code such as the following: private JUPanelBinding panelBinding = new JUPanelBinding("DeptEmpApp.DeptEmpModel", this);

This binding code is written automatically when the Panel Wizard runs (either when you explicitly run the Panel Wizard or when the JClient Form Wizard runs it).

In addition, the GUI elements such as text fields must be bound to the view object attributes. This is accomplished using the document property of the items. For example, when you view the values for a text field in the Property Inspector, you will see an entry for JClient Attribute Binding as follows:

If you select this value, the document property dialog will appear for the data model selection as shown in Figure 2. You select an attribute that will be bound to the text field and click OK.

Other manual steps you would take when filling out an empty panel follow:

1. Add containers and assign layout managers. The components that you add to the user interface must be placed inside container elements such as panels. Each panel must be assigned a layout manager that is responsible for its behavior when the container is resized. Usually, you create a set of containers inside of containers based on the requirements of the interface. Designing the container hierarchy requires knowledge about the layout managers and about the design of the application. At this stage, you also assign the properties of the layout manager, such as the gap between horizontal areas.

2. Add the user interface (UI) components. You add controls that the user interacts with, such as text fields and buttons, manually. It is important to place them in the proper container based on your design. One technique that Java programmers use is to initially lay out the components using the null (or no) layout manager. This layout manager imposes no repositioning or resizing behavior on its components, so you do not have to worry about those effects at this point in

Page 6: C J CLIENT AND JSP APPLICATIONS IN ORACLE9I JDEVELOPER · Creating a default, but functional BC4J layer in JDeveloper is easily accomplished by means of running the Business Components

the process. After all components are in the proper place, you can create additional containers as required and substitute the desired layout manager.

Figure 2. Document dialog

3. Set the component constraints property. The components are positioned within the layout manager using a property called constraints. For example, the BorderLayout manager allows you to define five areas within the container (East, Central, West, North, and South). To assign a particular component to a specific area, you set the component constraints property (for example, to North). Most layout managers only allow one component per area, so you may have to embed additional containers for additional components. Most layout managers do not allow you to set a specific X and Y position for a component because the layout manager is responsible for assigning those based on the panel’s shape and size. Therefore, performing precise layout in the UI Editor in JDeveloper is not as important as assigning the layout manager and constraints properties.

4. Set the component properties. Properties of components such as size, font, and label are manipulated on the Property Inspector. If there is a property of the object that does not appear in the Property Inspector, you can write set() code for the property in the Code Editor. As mentioned, the size and position properties of the component may be partially affected by the layout manager of the container in which it resides.

5. Add event code. The Property Inspector also allows you to create events for objects. For buttons and other event components, you can double click the event name (such as actionPerformed) in the Property Inspector to create the listener code and event stub code. You then need to fill in the stub with code that is specific to your need. Code that you would add might conditionally navigate to other forms or applications or to process a mouse click.

WHICH WIZARD IS BEST? This is an important question. The core of the answer is common sense: If the application that you need to create is close to what the JClient Form Wizard will create, this is the wizard to use. It is virtually guaranteed that the wizard will not fulfill 100 percent of the application’s requirements. Therefore, you will need to dig into its code and supplement or replace the defaults. This requires an understanding of how the generated code is built and structured. If the final application requires significant modification of the generated code, it is probably better to start from scratch without using the JClient Form Wizard.

Page 7: C J CLIENT AND JSP APPLICATIONS IN ORACLE9I JDEVELOPER · Creating a default, but functional BC4J layer in JDeveloper is easily accomplished by means of running the Business Components

Note

Another alternative for development using the wizards mentioned in this paper is to create your own wizard. The JDeveloper help system contains documentation about the Addin API that you use for this purpose. This requires substantial amount of effort and you need to weigh the benefits with the effort required.

JSP APPLICATIONS JavaServer Pages technology has become increasingly popular lately. This section provides a brief overview of the architecture JSP pages. As mentioned, the companion paper provides some more detail about the architecture, benefits and drawbacks of this style of deployment.

JSP PAGES JSP technology is a variation on servlet technology that mixes HTML language and Java language in the same source file. JSP pages have both a dynamic and static element to them, usually represented by the Java and HTML code, respectively. This mix allows the developer to easily code the parts of the application that do not change. For example, JSP code would include the <HTML> tag at the beginning and the </HTML> tag at the end of the page. It would also include all of the static links and boilerplate graphics and text.

When the user requests access to a JSP file stored on a web server, the web server passes the interpretation of the page to a JSP container program that runs a JVM on the server. The JSP container processes the JSP-specific tags, some of which may create additional HTML-formatted output. The container then mixes the static HTML tags (wrapped in print statements) with the output generated by the JSP tags and sends the entire page back to the browser.

Figure 3 shows JSP runtime process when a client browser requests a JSP file from the server (1), the server passes the request to the JSP Container (2), the JSP container compiles and runs the JSP file and accesses BC4J classes on the business tier server (3), the BC4J classes access the database (4), and pass messages back to the JSP application (5).

Figure 3. JSP runtime

Page 8: C J CLIENT AND JSP APPLICATIONS IN ORACLE9I JDEVELOPER · Creating a default, but functional BC4J layer in JDeveloper is easily accomplished by means of running the Business Components

The first time a JSP page is accessed, the server process creates a Java servlet file and compiles that file into bytecode in a .class file. For subsequent accesses, the .class file is cached on the server so that this compilation is not required unless the code is changed. The JSP container runs the .class file in its JVM session. The Java and .class files are generated dynamically from the JSP source code file. The BC4J layer sits on the application server and communicates with the database as in the other models.

CREATING JSP APPLICATIONS IN JDEVELOPER Developing JSP applications in JDeveloper is inherently different from developing Java applications and applets. Java applications and applets have a graphical design element to them, and you can drag and drop objects from the Component Palette into the Structure window or UI Editor. You can view and manipulate the properties of the components using the UI Editor and Property Inspector. These methods write source code but allow you to work with the code in a visual way.

When you use JDeveloper to work with a JSP application, you do not use the UI Editor or Property Inspector. Most of the work that you do is in the Code Editor. If there is a JSP file in the Code Editor, the Component Palette contains a list of pages that contain components available to your application, as shown here:

When you click a component in the toolbar, a dialog will open where you fill in properties about the elements that you want to create, as shown in Figure 4. When you complete the dialog, the tags will be written into the Code Editor at the cursor position.

The major visual part of the application results from HTML content that will most likely be developed using another tool, such as FrontPage or Dreamweaver. These tools can be used in combination with JDeveloper so that you can work on both visual design and JSP construction. A web designer can work separately on the complex layouts using these tools, and you can later merge her or his work with the Java code that you create in JDeveloper.

MORE SKILLS REQUIRED Work in JSP applications requires a broader range of knowledge than is required for work in Java applications or applets, for which you only need to know the Java language (in addition to database languages). In addition to knowledge of JSP tags, a typical JSP application requires familiarity with HTML, Java, JavaScript, and cascading style sheets. All of these are very approachable languages or technologies, but may require a bit of study and a good reference book before you become fully fluent and comfortable with development work in them.

Note

The JDeveloper wizards, editors, and viewers support different styles of JSP applications such as Oracle’s uIX (User Interface XML) and OJSP, and the industry-popular Struts framework. However, this paper concentrates on JDeveloper features as they apply to work with the BC4J Data Tags Library—a set of JSP tags that easily access BC4J objects.

Page 9: C J CLIENT AND JSP APPLICATIONS IN ORACLE9I JDEVELOPER · Creating a default, but functional BC4J layer in JDeveloper is easily accomplished by means of running the Business Components

JSP DEVELOPMENT STEPS The normal working process in JDeveloper consists of the following steps:

1. Create a text file using File | New and select JSP Page in the Web Tier\JavaServer Pages (JSP) category. This creates a default file with some sample JSP elements. The New JSP dialog allows you to name and assign a directory to the file.

2. Develop an HTML template, or look-and-feel. The JSP file that you create can incorporate an HTML template that contains the standard look-and-feel of your site. The HTML template might include a standard background graphic, a company logo in a standard position, a navigation bar containing links to the major areas of your site, a footer graphic, and links to contact information. The HTML layout work will be done in an appropriate tool, such as FrontPage.

Figure 4. BC4J data tag dialog

3. Add JSP tags that comprise the code using the pulldowns in the Component Palette. A JSP tag is a piece of code that can be made up of HTML-like tags or Java. It is interpreted by the JSP container running on the server. The main types of code that you will add to the JSP file are the following:

• HTML tags These are standard tags used to create browser pages. They are written into the JSP file just as they would be written into a normal HTML file.

• Standard JSP tags JSP elements use a tag syntax like HTML, but contain special characters (such as % signs) to distinguish them from HTML tags. The standard JSP tags created by Sun are documented on their web site. You need to enter these in the Code Editor because there is no Component Palette page for these tags.

• JDeveloper JSP elements JDeveloper provides the BC4J Data Tags Library (and other libraries such as uiXML and Struts) that contains tags that create HTML output and connect to BC4J objects.

4. View the file in the JSP Viewer as shown in Figure 5. This viewer is available from the right-click menu in the Code Editor or Navigator. It displays the standard HTML tags (and Java method calls for the web beans) as they will appear when the JSP page is run. In this example, a graphic tag has been added inside the header tag. The JSP Viewer allows you to quickly check the visual display of some of the HTML without running the JSP page. It does not show the data values inside the HTML code; you need to run the file to see the data as described in the next step.

Page 10: C J CLIENT AND JSP APPLICATIONS IN ORACLE9I JDEVELOPER · Creating a default, but functional BC4J layer in JDeveloper is easily accomplished by means of running the Business Components

5. Test the file using JDeveloper's built-in Oracle9iAS Containers for J2EE (OC4J) server. The pages will be displayed in your browser, and you will be able to check the design, interaction with the database, and user interface functionality. Make notes of the modifications needed to comply with the requirements.

6. Modify the code and test it again. This modify/test step continues throughout the development process. 7. Deploy the files to another server so that they may be available to users.

Figure 5. JSP Viewer

JSP WIZARDS AND DIALOGS The wizards and dialogs that create JSP files are started by selecting items under the Web Tier node in the New gallery (File | New). There are a number of categories under the Web Tier node that will create different types of files. The JavaServer Pages (JSP) node contains wizards or dialogs that will create generic JSP files (not specific to any tag library or framework). In that node, the JSP Page item creates a standard JSP page with basic HTML tags and some default text. The JSP Document item creates a JSP 1.2 document that will contain XML-style code. The JSP Page and JSP Document display a dialog that only requires a name. There are also Wizards in that node for creating web beans and tag libraries.

The BC4J data tags are supported by the JSP for Business Components category under the Web Tier node. This category contains options for creating a full application or for creating data pages. There are similar nodes under the Web Tier for other types of application server code. The BC4J data tags wizards require a bit of explanation.

BUSINESS COMPONENTS JSP APPLICATION WIZARD The New gallery item Complete JSP Application (in the Web Tier\JSP for Business Components category) runs the Business Components JSP Application Wizard (also called the BC4J JSP Application Wizard). The wizard requires minimal input: the client data model definition that specifies the application module; and view object and view link usages for which you need pages in the application. You can specify whether you want browse, query, and edit pages for each view usage. You can also specify whether you want a page for each view link. The wizard creates a fully-functional application.

For production systems, you will need to go beyond the defaults, and modify the code that the wizard creates. You can modify the cascading style sheet, JSP file component and HTML tags, and the component JSP files to change the behavior and appearance of the application.

The application wizard provides the “quick and dirty” application that may serve to demonstrate BC4J object editing, data administration, and even as a starting point for a more user-friendly application.

DATA PAGE WIZARD The Data Page Wizard is triggered from the New gallery items Browse & Edit Form, Browse Form, Query Form, and Starter Data Page (in the Client Tier\Swing/JClient for BC4J category). The wizard will create a page (or pages) that connects to a single view usage. All modes of the Data Page Wizard copy a number of supporting files (such as the cascading style sheet file)

Page 11: C J CLIENT AND JSP APPLICATIONS IN ORACLE9I JDEVELOPER · Creating a default, but functional BC4J layer in JDeveloper is easily accomplished by means of running the Business Components

into the project and create complete, working pages. The pages that the Data Page Wizard creates are similar to those that the Business Components JSP Application Wizard creates.

This wizard gives you a more controlled way to build an application. Each page is complete but, as with the Business Components JSP Application Wizard, you will need to modify its look-and-feel to fulfill your application requirements. You can build pages around the output from this wizard, or embed the pages that the wizard creates inside other pages.

Each of the modes of the Data Page Wizard creates a page or two as described next.

BROWSE & EDIT FORM The Browse & Edit Form selection creates a browse page such as the following that displays rows from a view usage in multi-record, grid table form with scroller links (Previous and Next).

Each row has a link for Delete and Edit. The Delete function deletes the row. The Edit function displays an edit form page that contains editable fields loaded with the values from that row such as that shown in Figure 6.

The edit page returns to the browse page where you can commit or rollback the changes. The browse page also contains a New link that loads the same edit form (with empty fields) where the user can enter a new row.

BROWSE FORM The Browse Form selection creates the same browse form without New, Edit, and Delete links. The browse form has scroller links for Previous and Next but no Commit and Rollback links.

QUERY FORM The Query Form selection creates a form with fields where the user can enter query criteria and search for matches. After the user clicks Search, a data table appears at the bottom of the page with the results as shown in Figure 7.

By default, there are no Edit, Delete, or New links on the browse area, but, if you create an edit page (or run the Data Page Wizard in Browse & Edit Form mode), you can link that page to the DataTable component by specifying the name of the edit form in the DataTable attribute edittarget.

STARTER DATA PAGE The Starter Data Page selection creates a page containing ApplicationModule and DataSource tags but with no specific data component tag. Therefore, if you run this JSP page, you will see nothing on the page. The purpose of this page is to give you a starting point for entering data component tags that is farther along than the file, which the generic JSP Page dialog creates.

Page 12: C J CLIENT AND JSP APPLICATIONS IN ORACLE9I JDEVELOPER · Creating a default, but functional BC4J layer in JDeveloper is easily accomplished by means of running the Business Components

Figure 6. Edit form

Figure 7. Query form with results

Page 13: C J CLIENT AND JSP APPLICATIONS IN ORACLE9I JDEVELOPER · Creating a default, but functional BC4J layer in JDeveloper is easily accomplished by means of running the Business Components

Tip

It is useful to examine the code that the Data Page Wizard and Business Components JSP Application Wizard creates to determine how JSP pages are constructed with these tags.

WORKING WITH BC4J DATA TAGS IN THE CODE EDITOR Once the wizards have created basic functioning code, you need to modify this code. When working with the BC4J Data Tags Library, you can use the tools in JDeveloper’s Code Editor to assist. Although you can type the code for BC4J data tags directly in the Code Editor, JDeveloper offers two tools that help ensure the correct spelling and syntax: the Component Palette and the JSP Data Binding tool.

Tip

The Code Editor offers context-sensitive help for custom JSP tags supplied with JDeveloper. For example, if you place the cursor inside a BC4J tag (such as “<jbo:ApplicationModule>”) and press F1, the help topic for ApplicationModule will be displayed.

COMPONENT PALETTE The Component Palette displays pages appropriate to JSP work when the topmost Code Editor window contains a JSP file. To activate a page, you select it from the pulldown list in the Component Palette bar. If the Component Palette is not visible, select View | Component Palette.

When you select a tag, a wizard will appear that steps you through filling out the required properties. When you click Finish, the wizard will enter the tag text at the cursor location in the Code Editor and will add attributes to the tag based on the properties that you completed in the wizard. You cannot run the wizard on an existing tag in the Code Editor. If you run the wizard again, you will have to fill in the tag properties again.

Tip

If you want to replace a tag entry in the Code Editor, select the tag’s text and click the tag in the Component Palette. After you fill out the wizard properties and click Finish, the new tag will replace the selected text.

COMPONENT PALETTE PLACEMENT AND APPEARANCE The Component Palette anchors by default on the right side of the IDE window. If you want more horizontal space in the Code Editor, you can drag the Component Palette to the top of the IDE (for example, under the Document Bar). This frees up the right side of the IDE so that you can expand the Code Editor. The Component Palette will appear with icons and names as in the following example:

If you select Icon View from the right-click menu on the Component Palette, the names will be hidden, and you will just see the icons for each component.

If you have not memorized the meaning of the icons, this particular view of the Component Palette may slow down your development, so you may want to leave the names displayed. You can switch back to the name and icon display by selecting List View from the right-click menu on the Component Palette.

Page 14: C J CLIENT AND JSP APPLICATIONS IN ORACLE9I JDEVELOPER · Creating a default, but functional BC4J layer in JDeveloper is easily accomplished by means of running the Business Components

Tip

The Component Palette offers the ability to “pin” the buttons. If you hold the SHIFT key while clicking a button, the tag will stay selected so that you can add more than one without reselecting the button. To unpin the button, click the Pointer button.

CODE SNIPPETS One of the Component Palette pages available to JSP pages is the Code Snippets page. This page allows you to select code that you have stored and named. For example, although the link to a cascading style sheet is not available on the HTML page of the Component Palette, you can add this to the Code Snippets page using the following steps:

1. Highlight the following line in the Code Editor window for a JSP page that you generated using the Data Page Wizard (or just type the line into an existing JSP page):

<LINK REL=STYLESHEET TYPE="text/css" HREF="bc4j.css">

2. In the Code Editor, select Add Code Snippet from the right-click menu. The code snippet dialog will appear. 3. Fill in the Name of code snippet field with the name, in this case “bc4j.css Reference.” The code snippet will be added to

the Component Palette’s Code Snippets page. To use a code snippet, place the cursor where you want the code to appear in the Code Editor, and click the code snippet’s button in the Component Palette. The code will be added to the file at the cursor position.

You can also create code snippets by selecting Add Component from the right-click menu on the Code Snippets page of the Component Palette. The right-click menu also contains selections for removing a component and displaying the properties of all components in all pages of the Component Palette. The properties dialog also allows you to modify the code in the code snippet.

JSP DATA BINDING TOOL The JSP Data Binding tool (shown in Figure 8) was new with release 9.0.3. It provides another method for adding BC4J data tags to the JSP file. Since it bypasses the wizard pages, you may find it faster for entering tags once you know the required elements and are familiar with the purpose of the tag. The JSP Data Binding tool appears by default on the right side of the screen when you select View | JSP Data Binding. You can close this window using the close window (“X”) icon in the top right corner of the palette window. This palette contains the following panes:

• Client Data Model This pane provides a hierarchical view of all client data model definitions available to the project. You use this pane to browse the view usages and their attributes. When you select a node in this pane, the Control Type pane is loaded with the components appropriate to that node.

• Control Type This pane contains the appropriate component tags for the node selected in the Client Data Model pane. When you select a control type, the Properties node changes to display the properties of that control.

• Properties This pane allows you to set values for the selected control’s properties. There are buttons in the toolbar for creating a client data model definition, editing the BC4J object selected in the Client Data Model pane, creating view objects and view links, and help.

To add a tag to the JSP file, you click the appropriate object in the Client Data Model pane, select the tag in the Control Type pane, fill out the properties, and drag the component from the Control Type pane to the place in the Code Editor where you want the tag to appear. After you drag the tag into the Code Editor, the properties will remain in the properties window in case you want to add another tag with the same properties.

One advantage of the JSP Data Binding tool over the Component Palette is that it bypasses the wizard. which may save you time . This tool also allows you to interact with the BC4J data tags by starting with the application module element instead of starting with the tag. Another advantage is that you can drag the tag and drop it where you want. The tag does not need to be placed at the cursor location as it does with the Component Palette. The JSP Data Binding tool only offers BC4J Data Tags library tags, so you will still need the Component Palette for other types of tags.

Page 15: C J CLIENT AND JSP APPLICATIONS IN ORACLE9I JDEVELOPER · Creating a default, but functional BC4J layer in JDeveloper is easily accomplished by means of running the Business Components

Figure 8. JSP Data Binding Tool

CONCLUSION This paper has discussed how to use JDeveloper to create two of the most popular styles of Java application development: Java client (Java applications and applets) and JSP pages. Oracle9i JDeveloper provides editors, J2EE-compliant libraries, and wizards that help you quickly create enterprise-quality applications in these and many other styles.