< Day Day Up > |
WebLogic Workshop (WLW) is a full-featured development environment that allows developers to build enterprise applications, Web applications, individual components , Enterprise JavaBeans (EJBs), or any combination of these elements. This chapter explores the WebLogic Workshop programming model and introduces enterprise application development. Specifically, WebLogic Workshop allows you to
The WLW Programming Model and Structured ProgrammingBefore you can develop applications with WebLogic Workshop, you must understand the Workshop programming model, shown in Figure 3.1. WebLogic Workshop applications are separated into a number of different layers . The topmost level of a Workshop application, the external interface layer, provides methods for accessing an application. Application functionality can be accessed tradition ally, typically by using a browser, through portal or Web applications, or directly using Web services or business processes via Web services. Figure 3.1. The WebLogic Workshop programming model.
The second level of the model shows the controls layer. Web applications, portals, and other applications access resources or business logic using various controls. Controls, a new concept introduced with WebLogic Workshop 1.0 and improved greatly with 8.1, provide an abstraction layer that simplifies the process of working with Java 2 Enterprise Edition (J2EE) or custom resources. Controls are completely integrated into the WebLogic Workshop IDE, and much of the application code, regardless of what the application makes available, is dedicated to working with controls in one fashion or another. Controls are a revolutionary step forward for application developers and component developers. For the consumer, controls provide both an IDE-based facade and a runtime behavior for accessing functionality. Workshop controls enable developers to access resources and business logic in a consistent, straightforward manner, as though the control is a simple Java object. Controls simplify interaction with resources by providing a common interface to all resources. For the developer, controls are Java classes annotated with Javadoc tags that integrate seamlessly into WebLogic Workshop. These Javadoc tags, along with specific file extensions, allow WebLogic Workshop to recognize a class as a control. The developer of a control, whether the control is packaged with WebLogic Workshop or custom developed, makes a set of core functionality available via standard Java methods. At runtime, the WebLogic Server engine creates instances of the control during the consuming application's life cycle. The runtime engine sets up and tears down the background instance, as required. As a result, all the drudgery and issues of accessing J2EE resources are hidden behind the control interface. The application developer needs to know only the simpler aspects of the Java language, and most method calls are handled in a sequential, rather than object-oriented, fashion. Figure 3.2 shows how workshop applications interface with controls. Annotations exist at the file, field, and method levels and apply to a variety of file types. Although WebLogic Workshop handles most annotations, knowing what annotations are and are not is helpful. These are the most common annotations:
Figure 3.2. The WebLogic controls model.
WebLogic Workshop provides two specific control types: Java controls , defined with a .jcs extension, that developers write to provide business logic and access other controls for creating logical units of business functionality, and resource or extensible controls , defined with a .jcx extension, which act as wrappers for traditional J2EE resources. In either case, a control can be used in page navigation, Web services, business processes, or from within another control. The lowest layer in the WebLogic Workshop programming model is the resource access layer. Resource controls are purchased from third-party vendors and used directly to access the functionality of resources based on the WebLogic Workshop wizards or to access J2EE functionality. WebLogic Workshop comes packaged with a large variety of controls, all ready to use directly out-of-the-box. Examples of packaged controls include the following, which are only a small subset of the available controls:
Resource controls come in two types: those used directly by dropping instances into your application and manipulating their properties, and those that you custom-configure using wizards. The rowset control is an excellent example of a custom-configured (not "developed") control. Using the RowSet Wizard, you can specify the database schema and table you need to access, and the wizard creates a class that encapsulates all the logic to access the specified database table using java.sql.Rowset objects. Page Flow FundamentalsFigure 3.1 depicted a high-level overview of how WebLogic Workshop applications are structured from a data access and logic perspective. However, when viewed from a navigation perspective, a Workshop application looks different. Figure 3.3 shows Workshop applications from a Model-View-Controller (MVC) perspective. Behind the scenes, Workshop applications use a Struts-based implementation to provide the presentation and Controller functionality known as Page Flow . In Workshop applications, controls provide the Model component and Page Flows provide the View and Controller components. Figure 3.3. The Model-View-Controller view of a Workshop application.
Page Flows enable developers to quickly, easily, and (perhaps most important) visually define page transitions between pages of an application. Page Flows are defined within a Page Flow Controller, indicated with a .jpf extension, as well as HTML and JSP pages. Pageflows representing the controller aspect of MVC applications, controls the model and HTML and JSP presentation. Figure 3.4 shows the Flow View for the simple entry page of the Wonderland Casino. Wonderland offers a number of services, including gaming, eating , accommodations, and relaxing . Figure 3.4. A simple Page Flow in Flow View.
Fundamentally, a Page Flow is composed of a presentation component via JSP or HTML, data made available through controls, and decision logic accessible through actions. These areas are managed using three specific constructs:
A fourth, and often overlooked, area of Page Flows is that of initial page population. Before users can make any decision about what page to move to next , they often need some data. Pages can display data based on Page Flow variables and Form beans, using a combination of NetUI JSP tags and XScript. NetUI tags are closely integrated into Page Flow and described in detail in Chapters 4, "Developing with Page Flow," and 6, "Introduction to WebLogic Workshop Controls and Components." In Page Flows, XScript is used as a mechanism for accessing variables. XScript expressions can be written to navigate arrays of data or arbitrary XML. Listing 3.1 shows the JSP page representing the starting point of the Wonderland Casino. The netui anchor tags shown in the second and third shaded code lines in Listing 3.1 render visually as URL links but provide the name of the action that the Controller should call when they're clicked. The first shaded code line shows an XScript expression accessing a pageFlow variable.
Listing 3.1. The index.jsp Page<!--Generated by WebLogic Workshop--> <%@ page language="java" contentType="text/html;charset=UTF-8"%> <%@ taglib uri="netui-tags-databinding.tld" prefix="netui-data"%> <%@ taglib uri="netui-tags-html.tld" prefix="netui"%> <%@ taglib uri="netui-tags-template.tld" prefix="netui-template"%> <netui:html> <head> <title> <netui:label value="{pageFlow.mainTitle}"/> Main Page. </title> </head> <body> <p> <h1><center> Welcome to the <netui:label value="{pageFlow.mainTitle}"/> . </center></h1> <table border="1"> <tr> <td>Would you like to:</td> </tr> <tr> <td> <netui:anchor action="gamble"> Try your luck at our tables of chance and skill!</netui:anchor> </td> </tr> <tr> <td> <netui:anchor action="relax">Relax in out fine spa!</netui:anchor> </td> </tr> </table> </body> </netui:html> Listing 3.2 shows portions of the Controller pictured in Figure 3.5. Examining Listing 3.2, you can see that the first line in the shaded code section defines the String variable used by index.jsp to display the main page caption. The netui:label JSP tag displays text and can take input from a variable via the datasource attribute ”in this example, the parent pageFlow variable mainTitle is used as the datasource. Two actions are defined in the shaded code section: begin and gamble . Examining the gamble action, you can see that the @jpf:forward annotation defines the page that the success operation should forward to on success. When the forward object is created, the @jpf:forward annotation directs the forward object to the Gambling.jsp page. All this code is created automatically when WebLogic Workshop is used to create the Page Flow. Listing 3.2. Portions of Controller.jpfimport com.bea.wlw.netui.pageflow.PageFlowController; import com.bea.wlw.netui.pageflow.Forward; /** * * @jpf:controller * @jpf:view-properties view-properties:: * <!-- This data is auto-generated. Do not hand-edit this section. --> . . . */ public class Controller extends PageFlowController { public String mainTitle ="Wonderland Casino"; /** * @jpf:action * @jpf:forward name="index" path="index.jsp" */ protected Forward begin() { return new Forward("index"); } /** * @jpf:action * @jpf:forward name="success" path="Gambling.jsp" */ protected Forward gamble(GambleForm form) { return new Forward("success"); } ... /** * FormData get and set methods can be overwritten by the Form bean editor. */ public static class GambleForm extends FormData { private String bet; private String table; public void setTable(String table) { this.table = table; } 4 public String getTable() { return this.table; } ... } Figure 3.5. A simple Page Flow in Action View.
Form beans are the most commonly used mechanism for gathering data from a page. To create them, you use the Form bean editor in Workshop. A Form bean can be added to a page by dragging a netui:form tag onto a JSP and then associating it with a Form bean. When a user clicks the Form button, the data is packaged up and provided to the action. Figure 3.5 shows the Action View of a simple Controller using a Form bean. The index page contains a NetUI form element that gathers gambling data. When the form's Gamble button is clicked, the GambleForm data is passed to the gamble action, and the action can access the data. PortalsPage Flows and controls, collectively known as Web applications, are the core content of a Web site. Portals are the mechanism through which content is put together and displayed to the user. As today's Web applications become increasingly more sophisticated, applications requiring specialized sales campaigns , a customized look and feel, personalized services, and similar features are becoming more important. WebLogic Platform 8.1 includes WebLogic Portal 8.1, which offers the following features:
Figure 3.6 shows a simple portal application with a custom header. Chapters 12, "Overview of Portal Applications," and 13, "Personalization of Portal Applications," detail how to create Portal-enabled applications and take advantage of portal services. Figure 3.6. A simple portal application with a custom header.
Web Services and Business Process IntegrationMany applications require integrated services. For all practical purposes, integration is the process of making various applications and systems work together seamlessly. Common integration tasks include
In support of integration, WebLogic Platform 8.1 includes WebLogic Integration (WLI) 8.1. WLI 8.1 includes a process management engine and tools for creating business processes, tools for administration, tools for creating and managing business processes that require human interaction (commonly referred to as worklists ), an XQuery-based transformation engine, and various messaging services. Chapter 11, "Working with Workflows," goes into detail about how to use and build business process definitions. WebLogic Workshop offers support for a full-featured Web services development environment, including accessing external Web services and creating new Web services. With WebLogic Workshop, you can create a control for accessing a remote service in minutes rather than hours. Figure 3.7 shows the Web Services Control Wizard dialog boxes for creating a Web service from the Web Services Description Language (WSDL) file published by a third party. All you need is access to the WSDL file, and Workshop can create controls to access both Remote Procedure Call (RPC) and document-style Web services. Chapter 9, "Working with Web Services," goes into depth about working with and building Web services and Web services controls. Figure 3.7. The Web Services Control Wizard dialog boxes.
Now you've seen a high-level view of a WebLogic Workshop application. In the following sections we'll look at it more closely. |
< Day Day Up > |