WebLogic Workshop Application Development Basics



Similar documents
BaanERP. BaanERP Windows Client Installation Guide

Desktop Management. Desktop Management Tools

ODBC. Getting Started With Sage Timberline Office ODBC

Domain 1: Configuring Domain Name System (DNS) for Active Directory

Configuring Additional Active Directory Server Roles

Domain 1: Identifying Cause of and Resolving Desktop Application Issues Identifying and Resolving New Software Installation Issues

Engineering Data Management

Baan Service Master Data Management

Domain 1: Designing a SQL Server Instance and a Database Solution

(VCP-310)

Authentication - Access Control Default Security Active Directory Trusted Authentication Guest User or Anonymous (un-authenticated) Logging Out

Neolane Reporting. Neolane v6.1

HP Asset Manager. Software version: Service Asset and Configuration Management

*The most important feature of MRP as compared with ordinary inventory control analysis is its time phasing feature.

5 Boolean Decision Trees (February 11)

CCH Accountants Starter Pack

SECTION 1.5 : SUMMATION NOTATION + WORK WITH SEQUENCES

Open M/SQL Developer Guide

Neolane Leads. Neolane v6.1

InventoryControl. The Complete Inventory Tracking Solution for Small Businesses

Business Rules-Driven SOA. A Framework for Multi-Tenant Cloud Computing

ContactPro Desktop for Multi-Media Contact Center

Security Functions and Purposes of Network Devices and Technologies (SY0-301) Firewalls. Audiobooks

BEA elink Adapter for Kenan Arbor/BP. User Guide

IT Support n n support@premierchoiceinternet.com. 30 Day FREE Trial. IT Support from 8p/user

Confidence Intervals for One Mean

Enhancing Oracle Business Intelligence with cubus EV How users of Oracle BI on Essbase cubes can benefit from cubus outperform EV Analytics (cubus EV)

PUBLIC RELATIONS PROJECT 2016

QUADRO tech. PST Flightdeck. Put your PST Migration on autopilot

iprox sensors iprox inductive sensors iprox programming tools ProxView programming software iprox the world s most versatile proximity sensor

Domain 1 - Describe Cisco VoIP Implementations

A Meta-Plugin for Bespoke Data Management in WordPress

In nite Sequences. Dr. Philippe B. Laval Kennesaw State University. October 9, 2008

E-Plex Enterprise Access Control System

CHAPTER 3 THE TIME VALUE OF MONEY

Hypergeometric Distributions

June 3, Voice over IP

TruStore: The storage. system that grows with you. Machine Tools / Power Tools Laser Technology / Electronics Medical Technology

Understanding Web Services- XML, WSDL, SOAP and UDDI. Preface

.04. This means $1000 is multiplied by 1.02 five times, once for each of the remaining sixmonth

Document Control Solutions

Definition. A variable X that takes on values X 1, X 2, X 3,...X k with respective frequencies f 1, f 2, f 3,...f k has mean

Message Exchange in the Utility Market Using SAP for Utilities. Point of View by Marc Metz and Maarten Vriesema

CREATIVE MARKETING PROJECT 2016

Chapter 10 Computer Design Basics

Now here is the important step

QUADRO tech. FSA Migrator 2.6. File Server Migrations - Made Easy

Professional Networking

PENSION ANNUITY. Policy Conditions Document reference: PPAS1(7) This is an important document. Please keep it in a safe place.

Conversion Instructions:

Xantaro Maintenance Services & Operations. XTAC User Guide. UK Edition

client communication

Domain 1 Components of the Cisco Unified Communications Architecture

INVESTMENT PERFORMANCE COUNCIL (IPC) Guidance Statement on Calculation Methodology

Introducing Rational Suite

Exchange Server 2010 Configuration (70-662) LearnSmart Exam Manual Copyright 2011 by PrepLogic, LLC. Product ID: Production Date: July 13, 2011

The Spring Web MVC Framework

How To Solve The Homewor Problem Beautifully

A Balanced Scorecard

Making training work for your business

Software Engineering Guest Lecture, University of Toronto

Measures of Spread and Boxplots Discrete Math, Section 9.4

CS100: Introduction to Computer Science

A Secure Implementation of Java Inner Classes

! encor e networks TM

Lesson 17 Pearson s Correlation Coefficient

Creating And Designing A Successful Portfolio Item Model By Owner

Safety Requirements engineering and Proof of implementation

hp calculators HP 12C Statistics - average and standard deviation Average and standard deviation concepts HP12C average and standard deviation

Discrete Mathematics and Probability Theory Spring 2014 Anant Sahai Note 13

Digital Enterprise Unit. White Paper. Web Analytics Measurement for Responsive Websites

BaanERP 5.0c. EDI User Guide

Static revisited. Odds and ends. Static methods. Static methods 5/2/16. Some features of Java we haven t discussed

e-trader user guide Introduction

The Forgotten Middle. research readiness results. Executive Summary

HP Asset Manager SAM Best Practice package

Flood Emergency Response Plan

INDEPENDENT BUSINESS PLAN EVENT 2016

INVESTMENT PERFORMANCE COUNCIL (IPC)

CCH CRM Books Online Software Fee Protection Consultancy Advice Lines CPD Books Online Software Fee Protection Consultancy Advice Lines CPD

Ethernet Option Board

Week 3 Conditional probabilities, Bayes formula, WEEK 3 page 1 Expected value of a random variable

Example 2 Find the square root of 0. The only square root of 0 is 0 (since 0 is not positive or negative, so those choices don t exist here).

Building Enterprise Applications with Windows Presentation Foundation and the Model View ViewModel Pattern

Analyzing Longitudinal Data from Complex Surveys Using SUDAAN

SOCIAL MEDIA. Keep the conversations going

For customers Key features of the Guaranteed Pension Annuity

Amendments to employer debt Regulations

RUT - Development manual

Equalizer Installation and Administration Guide

Symantec AntiVirus for Network Attached Storage Integration Guide

Transcription:

WebLogic Workshop Applicatio Developmet Basics IN THIS CHAPTER by Albert J. Sagaich, Jr. 3 IN THIS CHAPTER. WebLogic Workshop Programmig Basics. Creatig Applicatios ad Projects. Deployig ad Cofigurig Applicatios WebLogic Workshop Programmig Basics WebLogic Workshop (WLW) is a full-featured developmet eviromet that allows developers to build eterprise applicatios, Web applicatios, idividual compoets, Eterprise JavaBeas (EJBs), or ay combiatio of these elemets. This chapter explores the WebLogic Workshop programmig model ad itroduces eterprise applicatio developmet. Specifically, WebLogic Workshop allows you to Create WebLogic Workshop applicatios. Create WebLogic Workshop projects supportig portals, itegratio, cotrols, EJBs, Web Services, ad XML Schema. Create traditioal Web applicatios usig Page Flow for page avigatio ad Form beas for data gatherig ad display. Create portal applicatios that ca be the basis for a custom look ad feel as well as persoalizatio ad other portal features.

36 CHAPTER 3 WebLogic Workshop Applicatio Developmet Basics Create itegratio applicatios that ca be the basis for busiess process modelig, data trasformatio ad itegratio, ad multiparty orchestrated messagig. Create ad use simple cotrols ad Web services. The WLW Programmig Model ad Structured Programmig BUSINESS PROCESS For those ufamiliar with the term, a busiess process performs a well-defied set of busiess operatios to complete some task. A busiess process defiitio is a programmatic costruct that models a busiess process. WebLogic Workshop provides a mechaism for defiig busiess processes i the Itegrated Developmet Eviromet (IDE) kow as a Java Busiess Process Defiitio (JPD). WebLogic Workshop busiess process defiitios are discussed i Chapter 11, Workig with Workflows. Before you ca develop applicatios with WebLogic Workshop, you must uderstad the Workshop programmig model, show i Figure 3.1. WebLogic Workshop applicatios are separated ito a umber of differet layers. The topmost level of a Workshop applicatio, the exteral iterface layer, provides methods for accessig a applicatio. Applicatio fuctioality ca be accessed traditioally, typically by usig a browser, through portal or Web applicatios, or directly usig Web services or busiess processes via Web services. Exteral Cosumer (User ad other applicatio) Weblogic Workshop Applicatio Exteral Iterface Layer Portal Web Applicatio Workflow Web Service Direct or Custom Cotrols Layer Custom Cotrol Rowset Cotrol Web Service Cotrol EJB Cotrol Custom Cotrol Custom Cotrol Resource Access Layer Rowset Cotrol Applicatio View Cotrol TUX Cotrol EJB Cotrol Database Customer Relatioship Maagemet Custom Applicatio $$ EJB Web Service Exteral Resource Layer FIGURE 3.1 The WebLogic Workshop programmig model.

37 WebLogic Workshop Programmig Basics The secod level of the model shows the cotrols layer. Web applicatios, portals, ad other applicatios access resources or busiess logic usig various cotrols. Cotrols, a ew cocept itroduced with WebLogic Workshop 1.0 ad improved greatly with 8.1, provide a abstractio layer that simplifies the process of workig with Java 2 Eterprise Editio (J2EE) or custom resources. Cotrols are completely itegrated ito the WebLogic Workshop IDE, ad much of the applicatio code, regardless of what the applicatio makes available, is dedicated to workig with cotrols i oe fashio or aother. Cotrols are a revolutioary step forward for applicatio developers ad compoet developers. For the cosumer, cotrols provide both a IDE-based facade ad a rutime behavior for accessig fuctioality. Workshop cotrols eable developers to access resources ad busiess logic i a cosistet, straightforward maer, as though the cotrol is a simple Java object. Cotrols simplify iteractio with resources by providig a commo iterface to all resources. For the developer, cotrols are Java classes aotated with Javadoc tags that itegrate seamlessly ito WebLogic Workshop. These Javadoc tags, alog with specific file extesios, allow WebLogic Workshop to recogize a class as a cotrol. The developer of a cotrol, whether the cotrol is packaged with WebLogic Workshop or custom developed, makes a set of core fuctioality available via stadard Java methods. At rutime, the WebLogic Server egie creates istaces of the cotrol durig the cosumig applicatio s life cycle. The rutime egie sets up ad tears dow the backgroud istace, as required. As a result, all the drudgery ad issues of accessig J2EE resources are hidde behid the cotrol iterface. The applicatio developer eeds to kow oly the simpler aspects of the Java laguage, ad most method calls are hadled i a sequetial, rather tha object-orieted, fashio. Figure 3.2 shows how workshop applicatios iterface with cotrols. Aotatios exist at the file, field, ad method levels ad apply to a variety of file types. Although WebLogic JSR175 AS A DEFINITION OF CLASS METADATA The use of Javadoc aotatios to provide metadata is curretly beig stadardized ad reviewed as part of Java Specificatio Request (JSR) 175, A Metadata Facility for the Java Programmig Laguage. Workshop hadles most aotatios, kowig what aotatios are ad are ot is helpful. These are the most commo aotatios: @jc:<tagame> Aotatios for Java cotrols @jpd:<tagame> Aotatios for Java busiess processes @jpf:<tagame> Aotatios for Java Page Flows @jws:<tagame> Aotatios for Web services @commo:<tagame> Aotatios for commo features

38 CHAPTER 3 WebLogic Workshop Applicatio Developmet Basics Workshop applicatios Cotrols Back-ed Resources JMS Web Applicatio Database EJB JCA Workflow Other Cotrols Exposed WLW at develop time Maaged via WLS at rutime FIGURE 3.2 The WebLogic cotrols model. WebLogic Workshop provides two specific cotrol types: Java cotrols, defied with a.jcs extesio, that developers write to provide busiess logic ad access other cotrols for creatig logical uits of busiess fuctioality, ad resource or extesible cotrols, defied with a.jcx extesio, which act as wrappers for traditioal J2EE resources. I either case, a cotrol ca be used i page avigatio, Web services, busiess processes, or from withi aother cotrol. The lowest layer i the WebLogic Workshop programmig model is the resource access layer. Resource cotrols are purchased from third-party vedors ad used directly to access the fuctioality of resources based o the WebLogic Workshop wizards or to access J2EE fuctioality. WebLogic Workshop comes packaged with a large variety of cotrols, all ready to use directly out-of-the-box. Examples of packaged cotrols iclude the followig, which are oly a small subset of the available cotrols: Database ad Rowset cotrols providig support for easy access to existig databases Message-orieted cotrols for simplifyig iteractios with messagig-orieted middleware, such as Java Messagig Service (JMS) Busiess process (workflow) cotrols for defiig ad iteractig with busiess processes

39 WebLogic Workshop Programmig Basics EJB cotrols desiged to simplify accessig existig EJBs Web services cotrols for creatig ad accessig existig Web services Applicatio view cotrols for simplifyig access to uderlyig J2EE Coector Architecture (J2CA) adapters Third-party cotrols, icludig cotrols provided by parters ad other iterested parties Resource cotrols come i two types: those used directly by droppig istaces ito your applicatio ad maipulatig their properties, ad those that you custom-cofigure usig wizards. The rowset cotrol is a excellet example of a custom-cofigured (ot developed ) cotrol. Usig the RowSet Wizard, you ca specify the database schema ad table you eed to access, ad the wizard creates a class that ecapsulates all the logic to access the specified database table usig java.sql.rowset objects. Page Flow Fudametals Figure 3.1 depicted a high-level overview of how WebLogic Workshop applicatios are structured from a data access ad logic perspective. However, whe viewed from a avigatio perspective, a Workshop applicatio looks differet. Figure 3.3 shows Workshop applicatios from a Model-View-Cotroller (MVC) perspective. Behid the scees, Workshop applicatios use a Struts-based implemetatio to provide the presetatio ad Cotroller fuctioality kow as Page Flow. I Workshop applicatios, cotrols provide the Model compoet ad Page Flows provide the View ad Cotroller compoets. Page Flows eable developers to quickly, easily, ad (perhaps most importat) visually defie page trasitios betwee pages of a applicatio. Page Flows are defied withi a Page Flow Cotroller, idicated with a.jpf extesio, as well as HTML ad JSP pages. Pageflows represetig the cotroller aspect of MVC applicatios, cotrols the model ad HTML ad JSP presetatio. Figure 3.4 shows the Flow View for the simple etry page of the Woderlad Casio. Woderlad offers a umber of services, icludig gamig, eatig, accommodatios, ad relaxig. Fudametally, a Page Flow is composed of a presetatio compoet via JSP or HTML, data made available through cotrols, ad decisio logic accessible through actios. These areas are maaged usig three specific costructs: Form beas Capture page data ad are provided as iput to Actios. Form beas are cotaied withi Page Flows as JavaBea ier classes. Actios Cotai Java code implemetig avigatio logic, provide access to resources via cotrols, ad use form data via Form beas. Actios are implemeted as Cotroller methods, ad the Page Flow egie ca pass Form beas to them as iput. Forward objects Defie ad maage passig avigatio cotrol from actios to subsequet pages.

40 CHAPTER 3 WebLogic Workshop Applicatio Developmet Basics WebLogic Workshop Applicatio Resource Cotrol Resource Cotrol Database Resource Cotrol Resource Cotrol ERP Resource Cotrol Presetatio ad Cotroller $$ EJB Model Resources Method call Leged Method retur Asychroous Method FIGURE 3.3 The Model-View-Cotroller view of a Workshop applicatio. Actios (idicated page symbols) HTML pages or JSPs (idicated page symbols) Page trasitio (idicated with arrows) FIGURE 3.4 A simple Page Flow i Flow View.

41 WebLogic Workshop Programmig Basics A fourth, ad ofte overlooked, area of Page Flows is that of iitial page populatio. Before users ca make ay decisio about what page to move to ext, they ofte eed some data. Pages ca display data based o Page Flow variables ad Form beas, usig a combiatio of NetUI JSP tags ad XScript. NetUI tags are closely itegrated ito Page Flow ad described i detail i Chapters 4, Developig with Page Flow, ad 6, Itroductio to WebLogic Workshop Cotrols ad Compoets. I Page Flows, XScript is used as a mechaism for accessig variables. XScript expressios ca be writte to avigate arrays of data or arbitrary XML. Listig 3.1 shows the JSP page represetig the startig poit of the Woderlad Casio. The etui achor tags show i the secod ad third shaded code lies i Listig 3.1 reder visually as URL liks but provide the ame of the actio that the Cotroller should call whe they re clicked. The first shaded code lie shows a XScript expressio accessig a pageflow variable. LISTING 3.1 The idex.jsp Page OPENING AND BUILDING CHAPTER 3 SOURCE <!--Geerated by WebLogic Workshop--> <%@ page laguage= java cotettype= text/html;charset=utf-8 %> <%@ taglib uri= etui-tags-databidig.tld prefix= etui-data %> <%@ taglib uri= etui-tags-html.tld prefix= etui %> <%@ taglib uri= etui-tags-template.tld prefix= etui-template %> The complete source for the Chapter 3 examples ca be foud o the CD accompayig this book. To examie, build, or ru the example, choose File, Ope, Applicatio from the WebLogic Workshop meu, or double-click the.work file i the examplewebapp directory. <etui:html> <head> <title> <etui:label value= {pageflow.maititle} /> Mai Page. </title> </head> <body> <p> <h1><ceter> Welcome to the <etui:label value= {pageflow.maititle} />. </ceter></h1> <table border= 1 > <tr> <td>would you like to:</td> </tr> <tr> <td>

42 CHAPTER 3 WebLogic Workshop Applicatio Developmet Basics LISTING 3.1 Cotiued <etui:achor actio= gamble > Try your luck at our tables of chace ad skill!</etui:achor> </td> </tr> <tr> <td> <etui:achor actio= relax >Relax i out fie spa!</etui:achor> </td> </tr> </table> </body> </etui:html> Listig 3.2 shows portios of the Cotroller pictured i Figure 3.5. Examiig Listig 3.2, you ca see that the first lie i the shaded code sectio defies the Strig variable used by idex.jsp to display the mai page captio. The etui:label JSP tag displays text ad ca take iput from a variable via the datasource attribute i this example, the paret pageflow variable maititle is used as the datasource. Two actios are defied i the shaded code sectio: begi ad gamble. Examiig the gamble actio, you ca see that the @jpf:forward aotatio defies the page that the success operatio should forward to o success. Whe the forward object is created, the @jpf:forward aotatio directs the forward object to the Gamblig.jsp page. All this code is created automatically whe WebLogic Workshop is used to create the Page Flow. LISTING 3.2 Portios of Cotroller.jpf import com.bea.wlw.etui.pageflow.pageflowcotroller; import com.bea.wlw.etui.pageflow.forward; /** * * @jpf:cotroller * @jpf:view-properties view-properties:: * <!-- This data is auto-geerated. Do ot had-edit this sectio. -->... */ public class Cotroller exteds PageFlowCotroller { public Strig maititle = Woderlad Casio ;

43 WebLogic Workshop Programmig Basics LISTING 3.2 Cotiued /** * @jpf:actio * @jpf:forward ame= idex path= idex.jsp */ protected Forward begi() { retur ew Forward( idex ); } /** * @jpf:actio * @jpf:forward ame= success path= Gamblig.jsp */ protected Forward gamble(gambleform form) { retur ew Forward( success ); }... /** * FormData get ad set methods ca be overwritte by the Form bea editor. */ public static class GambleForm exteds FormData { private Strig bet; private Strig table; public void settable(strig table) { this.table = table; } 4 public Strig gettable() { retur this.table; }... } Form beas are the most commoly used mechaism for gatherig data from a page. To create them, you use the Form bea editor i Workshop. A Form bea ca be added to a page

44 CHAPTER 3 WebLogic Workshop Applicatio Developmet Basics by draggig a etui:form tag oto a JSP ad the associatig it with a Form bea. Whe a user clicks the Form butto, the data is packaged up ad provided to the actio. Figure 3.5 shows the Actio View of a simple Cotroller usig a Form bea. The idex page cotais a NetUI form elemet that gathers gamblig data. Whe the form s Gamble butto is clicked, the GambleForm data is passed to the gamble actio, ad the actio ca access the data. FIGURE 3.5 View. A simple Page Flow i Actio Portals Page Flows ad cotrols, collectively kow as Web applicatios, are the core cotet of a Web site. Portals are the mechaism through which cotet is put together ad displayed to the user. As today s Web applicatios become icreasigly more sophisticated, applicatios requirig specialized sales campaigs, a customized look ad feel, persoalized services, ad similar features are becomig more importat. WebLogic Platform 8.1 icludes WebLogic Portal 8.1, which offers the followig features: Portals Cofigurable desktop iterfaces to applicatio fuctioality. Portals eable you to defie sophisticated look ad feel, all packaged withi a Portal Desktop. Portlets Idividual pieces of fuctioality, based o HTML, Page Flows, Web services, ad other areas, that ca be reused with a Portal Desktop. Books Tabular defiitios of collectios of pages, used to group portlets ito cohesive uits. Look ad feel A fully customizable egie for defiig the look (styles, fots, images, ad so forth) ad feel (rederig ad behavior) of applicatios. Custom cotet maagemet This feature icludes services for loggig i, defiig user profiles, displayig profile-specific cotet, ruig specialized sales campaigs, ad tailorig cotet based o idividual user characteristics. Figure 3.6 shows a simple portal applicatio with a custom header. Chapters 12, Overview of Portal Applicatios, ad 13, Persoalizatio of Portal Applicatios, detail how to create Portal-eabled applicatios ad take advatage of portal services.

45 WebLogic Workshop Programmig Basics FIGURE 3.6 A simple portal applicatio with a custom header. Web Services ad Busiess Process Itegratio May applicatios require itegrated services. For all practical purposes, itegratio is the process of makig various applicatios ad systems work together seamlessly. Commo itegratio tasks iclude Creatig busiess processes Modelig complex, log-lived trasactios Covertig data betwee formats Implemetig multiparty orchestrated messagig Accessig data ad logic i exteral systems I support of itegratio, WebLogic Platform 8.1 icludes WebLogic Itegratio (WLI) 8.1. WLI 8.1 icludes a process maagemet egie ad tools for creatig busiess processes, tools for admiistratio, tools for creatig ad maagig busiess processes that require huma iteractio (commoly referred to as worklists), a XQuery-based trasformatio egie, ad various messagig services. Chapter 11, Workig with Workflows, goes ito detail about how to use ad build busiess process defiitios. WebLogic Workshop offers support for a full-featured Web services developmet eviromet, icludig accessig exteral Web services ad creatig ew Web services. With WebLogic Workshop, you ca create a cotrol for accessig a remote service i miutes rather

46 CHAPTER 3 WebLogic Workshop Applicatio Developmet Basics tha hours. Figure 3.7 shows the Web Services Cotrol Wizard dialog boxes for creatig a Web service from the Web Services Descriptio Laguage (WSDL) file published by a third party. All you eed is access to the WSDL file, ad Workshop ca create cotrols to access both Remote Procedure Call (RPC) ad documet-style Web services. Chapter 9, Workig with Web Services, goes ito depth about workig with ad buildig Web services ad Web services cotrols. FIGURE 3.7 The Web Services Cotrol Wizard dialog boxes. Now you ve see a high-level view of a WebLogic Workshop applicatio. I the followig sectios we ll look at it more closely. Creatig Applicatios ad Projects As we itroduced i Chapter 2, WebLogic Workshop creates J2EE eterprise applicatios cotaiig oe or more projects, libraries, modules, ad security roles. Before Workshop, just layig out properties ad cofigurig a applicatio required a cosiderable amout of effort. However, Workshop makes creatig ew Web applicatios quick ad easy. To create a basic Workshop applicatio, select File, New, Applicatio from the WebLogic Workshop meu. Figure 3.8 shows the New Applicatio dialog box. I this figure, (A) idicates the types of applicatios displayed i the right pae; by default, all applicatio types are show. The applicatio type list, labeled as (B), idicates the type of applicatio beig created. Default applicatios are basic Web applicatios ad iclude XML Schema support. A default applicatio cotais a core, but miimal, applicatio as a developmet startig poit. Empty applicatios iclude Web applicatio developmet support, but without a startig applicatio. Portal

47 Creatig Applicatios ad Projects applicatios are default applicatios that iclude additioal portal support services, icludig a data project supportig rules, campaigs, ad other portal features. Portal applicatios require a Portal-eabled server. Process applicatios are default applicatios that iclude itegratio ad busiess process services ad require a Itegratio-eabled server. The directory path, labeled (C), represets the root directory where the applicatio will be created. The ew applicatio ame, labeled (D), represets the ame of the applicatio as well as the topmost directory withi the root directory. The Server text box, labeled (E), represets the target server for the applicatio. A B C D E FIGURE 3.8 The New Applicatio dialog box. The Server text box is the most importat field i the New Applicatio dialog box. I the WebLogic Workshop programmig world, applicatios ad servers are tightly coupled. This tight couplig is a result of applicatios requirig specific services. Various servers provide differet services ad differet feature sets. For example, a applicatio might require WebLogic Portal or Itegratio support. Out of the box, WebLogic Workshop cotais server defiitios for the followig: Workshop A Web applicatio ad Schema-eabled server supportig Web applicatio developmet. Portal A WebLogic Portal eabled server, supportig Web applicatio ad portal services ad icludig all the services of the Workshop server. Itegratio A WebLogic Itegratio eabled server, supportig Web applicatio developmet usig busiess processes ad icludig all the services of the Workshop server. Ed2ed A WebLogic Platform eabled server cotaiig all the services previously metioed.

48 CHAPTER 3 WebLogic Workshop Applicatio Developmet Basics Whe buildig a applicatio for the first time, you must choose a server that provides the required services. If you ited to create a Web applicatio, select the Workshop server; otherwise, choose a server cosistet with your developmet eeds. Chapter 15, Takig Your Applicatios from Developmet to Productio, discusses the WebLogic Cofiguratio Wizard. This wizard eables users to create domai defiitios that ca iclude ay combiatio of the services required to support differet applicatio types. O disk, Workshop applicatios are maaged as expaded eterprise applicatios, but ca be packaged ito Eterprise Archives (EARs) easily by selectig Build, Build EAR from the mai meu. The build process is examied further i Buildig Applicatios, later i this chapter. STARTING WEBLOGIC SERVER FOR APPLICATION TESTING Remember, you caot test or debug applicatios without a ruig istace of WebLogic Server. Workshop has a umber of meu shortcuts for startig, stoppig, ad ruig the WebLogic Server Cosole from the Workshop eviromet. To start a istace of WebLogic Server for a applicatio, select Tools, WebLogic Server, Start WebLogic Server from the Workshop meu. To stop a ruig istace, select Tools, WebLogic Server, Stop WebLogic Server. To start the WebLogic Cosole, choose Tools, WebLogic Server, WebLogic Cosole. I additio, you ca deploy, udeploy, or redeploy applicatios by usig the Tools meu. After creatig a default Web applicatio, WebLogic Workshop displays the Applicatio pae (see Figure 3.9). Workshop Applicatios Breakdow Workshop Web applicatios are divided ito three major sectios. Oe major sectio is the Web applicatio itself, amed yourameweb by default, which cotais Cotroller.jpf A default Page Flow used as the startig poit of applicatio developmet. Error.jsp ad Idex.jsp are two default pages used by the Page Flow. resources A folder cotaiig a set of images, header ad template JSP files, ad associated stylesheets that ca be used as the basis of a commo look for a Web applicatio. Note that template.jsp ad header.jsp have a simplified look ad feel ad should ot be cofused with a portal look ad feel. WEB-INF A folder cotaiig all the XML-based applicatio deploymet descriptors, tag libraries, ad XML defiitios required to support Page Flows. Workshop maages almost all files i the WEB-INF folder, ad these files should ot be edited by had. Aother major sectio is the default Schema project, which cotais the followig: Schemas A folder used to house ay XML Schema files. Schemas ca be added to this project by drag ad drop. Newly added schemas are compiled, ad the the geerated XML Beas are added to the applicatio s libraries folder. Applicatio developers ca use the geerated XML Bea classes to create, delete, update, or otherwise maage associated XML.

49 Creatig Applicatios ad Projects XML deploymet descriptors Default Web applicatio Schema project Default Pageflow FIGURE 3.9 Supportig libraries ad security defiitios A Workshop applicatio with Schema ad basic Web applicatio support. The last major sectio is supportig libraries ad security defiitios commo to the applicatio folders: Libraries A folder cotaiig all support libraries. You ca add libraries to a project by draggig them ito the Libraries folder, which maps to the APP-INF\lib directory of a eterprise applicatio. Modules A folder cotaiig all deployed J2EE eterprise resources. The Modules folder cotais the applicatio.xml ad weblogic-applicatio.xml files, which Workshop maages automatically. This folder maps to the META-INF folder of a eterprise applicatio. Security Roles A folder cotaiig applicatio-defied security roles. The roles defied i a applicatio are ormally mapped to WebLogic Server groups. Security etries map to Security-role defiitios i the applicatio.xml file.

50 CHAPTER 3 WebLogic Workshop Applicatio Developmet Basics Workshop Projects As we saw i Chapter 2, workshop applicatios cotai oe or more projects. These are the most commo project types: Web Applicatio These projects are stadard Web applicatios packaged as Web Applicatio Archive (WAR) files. Web Applicatio projects cotai a default Page Flow ad support for creatig ew Page Flows, accessig existig cotrols, ad creatig ew cotrols. Typically, Web projects are used to make Web applicatios available for use with browsers, but the applicatio s fuctioality ca also be made available via Web services. Web Service These projects are targeted at makig applicatio fuctioality available as a Web service usig WSDL ad are packaged ito WAR files. Note that Web Service projects ca cotai Page Flows as well as Web services. Cotrol Cotrol projects cosist solely of cotrol classes, which are desiged to be used by other developers to create portals, Web applicatios, ad so forth. Cotrol projects are packaged ito Java archive (JAR) files ad ca be dropped ito aother applicatio s lib directory. EJB EJB projects cosist solely of EJBs ad ay support classes. EJB projects are packaged ito JAR files ad ca also be used by beig dropped directly ito aother applicatio s lib directory. Schema Schema projects cotai XML Schema files. Schema files are the compiled ito XML Beas, a geerated set of classes for maagig XML documets. XML Beas are a excitig ew BEA techology for creatig, accessig, ad workig with XML. XML Beas are examied i detail i Chapter 10, Hadlig Data i WebLogic Workshop: Workig with Schemas ad XML Beas. Java Project These projects cotai packages of Java classes. Java projects are used to create reuseable class libraries ad are packaged i JAR files. I additio, if you have purchased or dowloaded WebLogic Workshop Platform Editio, you ca create other project types, such as Process Process projects cosist of a default busiess process defiitio ad compile ito a JAR file that other projects or applicatios ca access. Process projects ca also be made available as Web services ad accessed by other Web services platforms. Portal ad Datasyc Portal projects cotai all the required ifrastructure for creatig portal applicatios. Creatig a portal project results i the creatio of a parallel datasyc project cotaiig rules, campaigs, placeholders, ad other portal-specific features. Portal applicatios are packaged ito EAR files.

51 Creatig Applicatios ad Projects To create a ew project, select File, New, Project from the Workshop meu. Alteratively, select your applicatio i the Applicatio tab, right-click, ad choose New Project. I the New Project dialog box (see Figure 3.10), select the type of project you would like to add. The type of project list, labeled (D) i Figure 3.10, displays subsets of the project types i the pae labeled (E). The All optio displays all project types, ad the other optios display subsets of project types. Select the type, labeled (D), ad the subtype, labeled (E), ad eter your ew project ame i the space labeled (F). A ew project is the added to Workshop, ad correspodig etries are added i the uderlyig XML deploymet descriptors. APPLICATION DEFAULT SERVICES Applicatios are created supportig a default set of services. For example, Web applicatios do ot support portal fuctioality by default. You ca add portal or other project support to applicatios or projects by selectig the project, right-clickig, ad choosig Istall, support service from the meu. Support service could be WebLogic Portal or some other ew service you wat to use i your applicatio. I this way, you ca later add Portal or Itegratio support to a core Web applicatio. Note that you might also eed to select a ew server because the core server might ot iclude the rutime services required to support the ew additios. A B C D E F FIGURE 3.10 The New Project dialog box.

52 CHAPTER 3 WebLogic Workshop Applicatio Developmet Basics With all the Workshop project types, the questio is Whe do you use oe project type versus aother? Whe you eed to build a portal project, the aswer is clear. However, as a rule of thumb, you should use a differet project wheever you are creatig reuseable uits of fuctioality or to separate urelated fuctioal areas. As we examie cotrols, portals, itegratio ad other project ad applicatio types we will also examie whe it is appropriate to create a ew project or applicatio, ad whe to exted the curret applicatio. INSTALLING APPLICATION FUNCTIONALITY SHOP TALK WebLogic Workshop is flexible i what kid of project to create. Web applicatios, portal projects, ad process projects are the orm. However, what happes if you wat a combiatio project, oe that perhaps spas portals ad workflows? Oe of the simplest ways to add fuctioality to a project is to select the root project, right-click, ad choose Istall. For example, you ca isert portal support ito a Web applicatio by choosig Istall, Portal. Ufortuately, istallig ew support ito a existig applicatio is somewhat of a problem. Depedig o the combiatio of resources, ot everythig works as plaed, ad it s ever clear what the root cause is. So how ca you create a project ad be sure it will support the features you wat? Practice has show that the best way to develop a applicatio is to start with the simplest project that supports the job at had. I practice, that meas creatig cotrols (EJB, busiess process, or geeral) withi their ow projects, uit testig i a applicatio that supports oly those features you wat, ad the ultimately creatig a overall applicatio that supports all the features previously tested as stadaloe ad itegrates them together. Use the followig guidelies: Create custom, rowset, ad EJB cotrols i cotrol projects. Uit test i Web applicatios. Create busiess process cotrols i busiess process cotrol projects. Delegate all backgroud processig to custom cotrols. Place busiess logic oly i busiess process cotrols. Create portals ad portlets i portal projects. Add oly tested cotrols to portal projects. Create overall applicatios that start with portal or busiess process support. Istall other fuctioality to the applicatio as required. Add tested logic via cotrols projects. Accessig ad Exposig Data via Cotrols Applicatios, whether they are desiged to support Web services or be accessed as Web or portal applicatios, require data as cotet ad for decisio logic. I Workshop applicatios, logic ad data are provided by cotrols, which are the heart of ay WebLogic Workshop applicatio. Figure 3.2 itroduced the Workshop cotrols model; Figure 3.11 shows a deeper view. Remember, workshop supports two differet types of cotrols: resource or extesible cotrols (based o J2EE resources), resources, ad custom cotrols writte by developers.

53 Creatig Applicatios ad Projects Custom cotrols are ormally used to ecapsulate data access or add busiess logic. To the developer, cotrols look much like stadard Java objects; however, i additio to traditioal methods, cotrols provide a umber of other capabilities, such as Asychroous method ivocatio The ability to call a log-ruig method ad retur immediately while the method cotiues i the backgroud. (This is show as a slashed arrow poitig ito the cotrol i Figure 3.11.) Callback method The ability to ivoke a method back to the callig cliet from a cotrol. (This is show as a slashed arrow poitig out of the cotrol i Figure 3.11.) Coversatios The ability to call methods that start, cotiue, ad ed a coversatio. Trasactio support Cotrol methods are a implicit part of a trasactio without ay developer work. Oe area that s becomig more importat i messagig is coectivity. Three specific types of coected behavior ca occur i today s etworks: fully coected, i which the cliet ad server are coected all the time; discoected, i which the cliet is ever coected to a server; ad partially coected, i which the cliet is sometimes coected to the server ad sometimes ot. The cotrol s rutime egie has support specifically targeted toward coectivity, amely the capability to maage a coversatio. Cotrols ca clearly defie what methods start, cotiue, ad ed a coversatio. More importat, cotrols provide mechaisms for obtaiig coversatio IDs so that applicatios ca discoect ad the later reestablish a coversatio. The ability to reestablish a coversatio is key to supportig a partially coected etwork model. Coversatios, asychroous methods, ad callbacks are covered i detail i Chapters 7, Usig the NetUI Tag Library Toolbox to Develop Sophisticated JSPs, 9, Workig with Web Services, ad 11, Workig with Workflows. Custom Cotrol State it xxx Strig yyy public it ormal () { // code } Public void asych() { //log ruig process } callback.doe(args); Resource Cotrol Custom Cotrol Resource Cotrol Resource Cotrol Resource Cotrol Custom Cotrol Database ERP $$ EJB FIGURE 3.11 A deeper look at cotrols.

54 CHAPTER 3 WebLogic Workshop Applicatio Developmet Basics Addig Cotrols to Page Flows The two most commo uses of cotrols are to gather data for display ad to make a logic decisio. To use a cotrol, you must add it to a Page Flow, ope a actio, ad call methods o the cotrol. Figure 3.12 shows two methods of addig a cotrol to a Page Flow. If the cotrol is part of the same applicatio, it ca be added by draggig the associated.jcx (Java extesible cotrol) or.jcs (Java custom cotrol) file ito the right side of a Page Flow s Actio View. Otherwise, you ca right-click i the right side of a Page Flow Actio View, select Cotrols, ad the add the cotrol. I either case, Workshop the prompts for the variable ame of the ew cotrol ad adds the cotrol to your applicatio. Listig 3.3 shows the code aotatios added to a Cotroller whe a cotrol is added. Cotrols ca the be accessed i actios like regular Java classes. A B FIGURE 3.12 Addig a cotrol to a Page Flow. LISTING 3.3 Aotatios Markig a Variable As a Cotrol public class Cotroller exteds PageFlowCotroller { /** * @commo:cotrol */ private cotrols.weather weather; /**

55 Creatig Applicatios ad Projects LISTING 3.3 Cotiued * @commo:cotrol */ private db.games gamesdbctrl; Accessig Databases with Rowsets Oe of the most commo types of cotrols is the rowset cotrol. The GamesDBCtrl show i the previous example is a simple RowSet cotrol ehaced to retur value objects. Rowset cotrols are based o the java.sql.rowset iterface ad provide a geeric mechaism for accessig database data over a etwork. Rowsets are derived from the java.sql.resultset class ad iherit much of the paret behavior. Rowsets ca be used to add data, query for data, traverse rows of data, ad delete data. The RowSet Wizard geerates several methods; the followig two methods are used to read data: RowSet getalltblename(databasefilter) This method retur all rows for a give table ad is filtered based o the database filter used as iput to a where clause. Note that eve if o filterig is required, you must provide a DatabaseFilter. RowSet detailstblename(key) This method returs the requested row based o the supplied key. Rowset data is accessed by usig oe of the type-specific rowset methods, a geeric example of which is show here. All rowset accessor methods use the followig form: Type gettype(strig ColName); I this form, type ca be Strig, It, Double, Float, Short, ad so o. See the java.sql.rowset documetatio for a complete list. Rowsets ca retur multiple rows of data. After a select clause, rowsets are iitially positioed before the first row. You ca iterate over a rowset by usig the ext() method. The Woderlad Casio is actually made up of a umber of casios. Descriptive data about the casios, games, hotels, ad so o is stored i a database that could be accessed by usig RowSet objects. The WONDERLAND.CASINOS table cotais the complete list. Its SQL defiitio is show here: CREATE TABLE WONDERLAND. CASINOS ( ID INT IDENTITY, NAME VARCHAR(20), DESCR VARCHAR(512) );

56 CHAPTER 3 WebLogic Workshop Applicatio Developmet Basics Assumig you have a RowSet object that cotais all the casios, you could traverse the list usig the followig: While (alldata.ext()) { System.out.pritl( ID= + alldata.getit( ID ); System.out.pritl( Name= + alldata.getstrig( NAME ); System.out.pritl( Desc= + alldata.getstrig( DESCR ); } WONDERLAND CASINO SAMPLE DATA The Woderlad Casio database defiitio is i the {CDROM}:\db directory o this book s CD. You ca add the Woderlad database to PoitBase, the database tool packaged with WebLogic Workshop, by ruig the mkdb.cmd commad script. First, you eed to edit the set-dbev.cmd script to poit to your BEA istall directory. To ru the script, ope a commad prompt, ad copy the scripts to a directory where they ca be edited. Edit set-dbev.cmd ad the ru mkdb.cmd. Additioally, if PoitBase is ruig somewhere other tha localhost:9093/ workshop, you eed to update the pbcmd.cmd script appropriately. The use of NetUI tags to preset data is covered i detail i Chapter 7. However, you could easily display the etire list of RowSet data usig a etui-data:repeater tag i a JSP. Assumig you retured a rowset of data from the Casios table defied i a Page Flow as public RowSet casios, you could access the data as a table usig the code show i Listig 3.4, with importat lies shaded. LISTING 3.4 The etui-data:repeater Tag <etui-data:repeater datasource= {pageflow.casios} > <etui-data:repeaterheader> <table border= 1 > <tr> <td><b>id</b></td> <td><b>name</b></td> <td><b>descriptio</b></td> </tr> </etui-data:repeaterheader> <etui-data:repeateritem> <tr> <td> <etui:label value= {cotaier.item.id} /> </td> <td> <etui:label value= {cotaier.item.name} />

57 Creatig Applicatios ad Projects LISTING 3.4 Cotiued </td> <td> <etui:label value= {cotaier.item.descr} /> </td> </tr> </etui-data:repeateritem> <etui-data:repeaterfooter> </table> </etui-data:repeaterfooter> </etui-data:repeater> Addig ad Deletig with Rowsets I additioal to readig data, rowsets support deletig, isertig, ad updatig data. The Casio Maiteace departmet has requested addig ew fuctioality to the Woderlad Web site to support listig, addig, ad deletig casios. A ew Page Flow, CasioMaiteace, has bee added to the Woderlad applicatio. It supports listig, addig, ad deletig casio table etries. To add a etry to a rowset, do the followig: 1. Obtai a template row by usig detailstblnametemplate(). 2. Update the row values. 3. Isert the ew row ito the rowset. 4. Isert the rowset cotets ito the database. Listig 3.5 shows a example of these steps. LISTING 3.5 The doadd Actio of CasioMaiteaceCotroller.jsp protected Forward doadd(addform form) { Strig ame = form.ame; Strig descriptio = form.descriptio; try { RowSet ewcasio = casiosdb.detailscasiostemplate(); ewcasio.updatestrig( NAME,ame); ewcasio.updatestrig( DESCR,descriptio); ewcasio.isertrow(); // add the row ito the rowset casiosdb.isertcasios(ewcasio); // add the row ito the db } catch(sqlexceptio sqle) { System.out.pritl( Uexpected SQLExceptio o add: +sqle);

58 CHAPTER 3 WebLogic Workshop Applicatio Developmet Basics LISTING 3.5 Cotiued } retur ew Forward( success ); } Deletig a row from a database follows a similar patter. To delete a row, follow these steps: 1. Obtai a rowset cotaiig the row based o the row s key. 2. Set the rowset to the row you wat to delete. 3. Delete the row from the rowset. 4. Delete the row from the database. Listig 3.6 shows a example of these steps. LISTING 3.6 The dodelete actio of CasioMaiteaceCotroller.jsp protected Forward dodelete(deleteform form) { Strig id = form.id; try { RowSet row = casiosdb.detailscasios(ew Iteger(id)); row.absolute( 1 ); row.deleterow(); casiosdb.deletecasios(row); } } catch (SQLExceptio sqle) { System.out.pritl( Uexpected SQLExceptio o delete: +sqle); } retur ew Forward( success ); Creatig Simple Rowset Cotrols Rowset cotrols are the heart of ay database applicatio. There are, i fact, two types of database access cotrols. Database cotrols, which are similar to rowset cotrols, require all data access to be coded by had. Rowset cotrols go a step further tha database cotrols, i that they provide a core set of access methods, based o java.sql.rowsets, for accessig data. Developers are free to add fuctioality, but a set of core methods are supplied.

59 Creatig Applicatios ad Projects To create a rowset cotrol, select a folder where the cotrol will be created ad follow these steps: A. & B. Select File, New, Other File Types from the Workshop meu (see Figure 3.13). C. Select Busiess Logic i the left pae. D. Select RowSet Cotrol i the right pae (see Figure 3.13), ad click Create. A B C D FIGURE 3.13 Creatig a rowset cotrol. E. Eter the cotrol variable ame. F. Select a appropriate datasource. G. Select the methods to create, either Query ad Update a Database Table (for traditioal tables) or Query a View or Table (o update methods geerated). The remaider of the steps for addig a rowset cotrol are show i Figure 3.14.

60 CHAPTER 3 WebLogic Workshop Applicatio Developmet Basics G H J I FIGURE 3.14 Selectig methods, colums, ad a primary key source i the RowSet Cotrol Wizard. H. Select the schema ad table ame, ad click Next. I. Select the colums to iclude, ad click Next. J. Select the primary key mechaism, ad click Create. Whe you re fiished, a ew rowset cotrol is created i the folder you selected. The ew cotrol ca be used to access the table from a Page Flow or aother cotrol.

61 Deployig ad Cofigurig Applicatios Deployig ad Cofigurig Applicatios To this poit, you ve bee workig with applicatios without uderstadig how they ca be built or deployed. Wheever you make a chage to a applicatio, WebLogic Workshop automatically sychroizes with the ruig istace of WebLogic Workshop. Buildig Applicatios Before a applicatio ca be ru, it must be compiled. WebLogic Workshop ca build applicatio compoets automatically or o demad. I the Workshop eviromet, buildig a applicatio is more the just compilatio. Because applicatios cotai aotatios, these aotatios must be reviewed, the compoets compiled, supportig classes created ad cofigured, ad more. WebLogic Workshop applicatios ca be i developmet or productio modes. I developmet mode, all compoets are compiled automatically as they chage. I productio mode, applicatios or compoets must be built usig the commadlie wlwbuild.cmd scripts or Workshop s Build, Applicatio, Build, EAR or Build, Project, project ame meus. You ca chage a applicatio s or project s properties by selectig the applicatio or project, right-clickig, ad the choosig Properties. Figure 3.15 shows the Applicatio Properties dialog box. FIGURE 3.15 The Applicatio Properties dialog box for the chapter3 applicatio.

62 CHAPTER 3 WebLogic Workshop Applicatio Developmet Basics Mappig Applicatios ad Projects to Directories WebLogic Workshop maps directly to a EAR file. Figure 3.16 shows the directory structure of the chapter3 sample Workshop Web applicatio. Table 3.1 maps WebLogic Workshop folders to the directories o disk. FIGURE 3.16 Applicatio directory structure. TABLE 3.1 Directory to Applicatio Mappig DIRECTORY OR FILE chapter3webapp.work.workshop APP-INF\lib chapter3web chapter3web\web-inf Schemas META-INF WORKSHOP APPLICATION EQUIVALENT AND CONTENTS Workshop applicatio cofiguratio file. Do ot edit or delete this file. Files ad classes geerated by Workshop. Not displayed. Locatio for all project JARs. Maps to Applicatio\lib. Ay JAR files added to this directory are added to the applicatio s class path. Schema ad other projects that produce JAR files place them here. Actual applicatio cotets. Maps to chapter3\chapter3web\. Maps to chapter3\chapter3web\web-inf. All tag libraries ad Web applicatio deploymet descriptors are located here. Schema project. Maps to chapter3\schemas. Maps to chapter3\modules. Cotais all applicatio-level deploymet descriptors maaged by WebLogic Workshop. I Brief I this chapter, you leared that Workshop supports the creatio of several applicatio types, icludig Web applicatios, Schema, portals, ad busiess processes. The WebLogic Workshop programmig model is the uderlyig basis for all Workshop applicatios. Its costituet parts (Page Flow, cotrols, ad so o) are based o Struts ad the MVC patter ad are used to model applicatio fuctioality.

63 I Brief Applicatios ad projects are the heart of WebLogic Workshop developmet. Projects are used to cotai Page Flows, cotrols, ad other compoets of a applicatio ad map directly to EAR format o disk. Oe of the most commo types of cotrols is the rowset cotrol, which ca be used to add data, query for data, traverse rows of data, ad delete data.