Sei sulla pagina 1di 16

OracleAS 10g R3: Build Java EE Applications I

Volume I Student Guide

D18378GC20 Edition 2.0 March 2007 D49830

Authors
Jeff Gallus Gary Williams

Copyright 2007, Oracle. All rights reserved. Disclaimer This document contains proprietary information and is protected by copyright and other intellectual property laws. You may copy and print this document solely for your own use in an Oracle training course. The document may not be modified or altered in any way. Except where your use constitutes "fair use" under copyright law, you may not use, share, download, upload, copy, print, display, perform, reproduce, publish, license, post, transmit, or distribute this document in whole or in part without the express authorization of Oracle. The information contained in this document is subject to change without notice. If you find any problems in the document, please report them in writing to: Oracle University, 500 Oracle Parkway, Redwood Shores, California 94065 USA. This document is not warranted to be error-free. Restricted Rights Notice If this documentation is delivered to the United States Government or anyone using the documentation on behalf of the United States Government, the following notice is applicable: U.S. GOVERNMENT RIGHTS The U.S. Governments rights to use, modify, reproduce, release, perform, display, or disclose these training materials are restricted by the terms of the applicable Oracle license agreement and/or the applicable U.S. Government contract. Trademark Notice Oracle, JD Edwards, PeopleSoft, and Siebel are registered trademarks of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.

Technical Contributors and Reviewers


Ken Cooper Douglas Clarke Pam Gamer Kate Heap Taj Islam Raghu Kodali Lynn Munsinger Frank Nimphius Glenn Stokol Volker Zell

Editors
Amitha Narayan Arijit Ghosh

Graphic Designer
Satish Bettegowda

Publishers
Michael Sebastian Almeida Nita Brozowski Sujatha Nagendra

Contents

Preface I Introduction Course Objectives I-2 Course Environment I-3 Course Overview I-4 About the Course Application I-7 Service Request Schema I-8 Java EE: Overview Objectives 1-2 Java Platform, Enterprise Edition 1-3 Java EE Platform 1-4 Distributed Multitiered Applications 1-5 Java EE Architecture 1-6 Benefits of the Java EE Platform 1-8 Java EE Components 1-10 Java EE 5.0 Components 1-11 Business-Tier Components 1-12 Enterprise JavaBeans (EJB) 1-13 Types of EJB 1-15 Java Persistence API 1-16 Web Services 1-17 Client-Tier Components 1-18 Java EE Web-Tier Components 1-19 What Is a Servlet? 1-21 What Is a JavaServer Page? 1-22 What Is JavaServer Faces? 1-23 Web-Tier Components: Summary 1-24 Java EE Communication APIs 1-25 Java EE Server 1-26 Java EE Applications 1-28 Packaging Java EE Applications 1-29 Packaging Java EE Application Components 1-30

iii

Oracle Application Server Containers for J2EE (OC4J) 1-31 OC4J Architecture 1-32 Java EE Application Deployment to Oracle Application Server 10g 1-33 Security in Java EE Applications 1-34 Using Deployment Descriptors for Declarative Security 1-35 JDeveloper and Java EE 1-36 Oracle JDeveloper 10g Environment 1-37 Oracle JDeveloper 10g Visual Design Tools 1-38 Summary 1-39 2 Designing Java EE Applications Objectives 2-2 Realizing Benefits of Java EE 2-3 Java EE Issues 2-4 Java EE Design Patterns 2-5 The MVC Design Pattern 2-6 The Model 2-7 The View 2-8 The Controller 2-9 MVC in Oracle Application Server 10g Containers for Java EE (OC4J) 2-10 Struts: Overview 2-11 Struts Components 2-12 Struts Page Flow Design 2-13 JSF: Overview 2-15 Oracle Application Development Framework (ADF) 2-16 Oracle ADF Implementation 2-17 Oracle WebCenter Suite 2-18 Summary 2-20 Practice Overview: Identifying MVC components 2-21 Creating the Persistence Layer Objectives 3-2 What Is Persistence? 3-3 Persistence: Overview 3-4 Persistence Layer 3-5 What Are POJOs? 3-6 EJB 3.0 - Java Persistence API 3-7 JPA Entities 3-8
iv

Entity Annotations 3-9 How Do JPA Entities Work? 3-10 Java Persistence API at Work 3-11 JPA O/R Mapping 3-12 Mapping Types 3-13 Specifying Object Relational (O/R) Mapping 3-14 Mapping Relationships Between Entities 3-15 Managing Persistence of JPA Entities 3-16 Entity Manager 3-17 JPA Entity Manager 3-19 Life Cycle of an Entity 3-20 Persistence Context and Scope 3-21 Manipulating Records with JPA 3-22 Writing Basic JPA QL SELECT Statements 3-23 Creating JPA Entities 3-24 Summary 3-25 Practice Overview: Developing EJBs 3-26 4 Implementing Business Logic Objectives 4-2 What Is a Session Bean? 4-3 Session Beans and JPA Entities 4-4 What Session Beans Do 4-5 Stateless and Stateful Session Beans 4-6 Life Cycle of a Stateless Session Bean 4-7 Life Cycle of a Stateful Session Bean 4-8 Stateless Session Bean: Facade 4-9 Implementing JPA Queries 4-10 Session Bean: Interface 4-11 Stateful Session Bean: Example 4-12 EJB Client 4-13 Interceptor Methods and Classes 4-14 Creating a Session Facade Bean in JDeveloper 4-15 Adding Methods to the Bean 4-16 Summary 4-17 Practice Overview: Developing Session Facade Beans 4-18 Implementing the Web Tier with Servlets Objectives 5-2 Overview 5-3
v

About Java Servlets 5-4 Principal Features of Servlets 5-5 Life Cycle of Servlets 5-6 HTTP Servlets 5-7 Inside an HTTP Servlet 5-8 The doGet() Method 5-9 The doPost() Method 5-10 The HttpServletRequest Object 5-11 The HttpServletResponse Object 5-12 HttpSession 5-13 Session Objects 5-14 Methods for Invoking Servlets 5-15 Handling Input: The Form 5-16 Handling Input: The Servlet 5-17 Initialization and Destruction 5-18 Error Handling 5-19 Debugging a Servlet 5-20 JDeveloper Environment 5-21 Servlet Mapping 5-22 Servlet Mapping in JDeveloper 5-23 Invoking a Servlet 5-24 Specifying Java EE Web Module Settings 5-25 Summary 5-26 Practice: Overview 5-27 6 Creating the Web Tier Using JavaServer Pages Objectives 6-2 JavaServer Pages 6-3 Comparing Servlets and JSPs 6-4 Invoking JSPs 6-5 Date JSP 6-6 Date Servlet 6-7 Automated JSP Features 6-8 JSP Life Cycle 6-9 Basic JSP Elements 6-10 Declarations 6-11 Expressions 6-13 Scriptlets 6-14 Implicit Objects 6-15 Example 6-17

vi

Directives 6-19 include: Example 6-20 page Directive 6-21 JSP and JavaBeans 6-23 Using JavaBeans with JSP 6-24 scope Attribute of <jsp:useBean> Tag 6-26 Accessing and Setting Bean Property 6-27 JSP XML Document 6-29 Traditional Syntax Versus XML Syntax 6-30 JSP Segments 6-32 JDeveloper and JSPs 6-33 Summary 6-34 Practice Overview: Developing JSPs 6-35 7 Creating the Web Tier Using JavaServer Faces Objectives 7-2 JSF: Overview 7-3 JSF: Benefits 7-4 Key Terms 7-5 JSF Architecture 7-6 JSF Components 7-8 JSF UI Components 7-9 JSF Component Architecture 7-10 Tag Handlers and Component Trees 7-11 Tag Libraries 7-12 Configuration Files 7-13 JSF Renderers 7-14 Managed Beans 7-15 Expression Language 7-16 Life Cycle of a JSF Page 7-17 JSF Life Cycle: Initial Request 7-18 JSF Life Cycle: Postback 7-19 Formal Phases: JSP 7-21 Using JSF Tag Libraries 7-22 JSF Applications 7-23 JSF and JDeveloper 10.1.3 7-24 JSF Navigation Diagram 7-26 Summary 7-27 Practice Overview: Developing JSF Pages 7-28

vii

Binding Data in an Application Objectives 8-2 ADF Architecture 8-3 ADF Model (ADF Databinding) 8-4 Types of Data Controls 8-5 Model Layer Components 8-6 Creating a Data Control 8-7 Generated Files in the Data Model Project 8-8 Data Control Palette 8-9 Creating Bindings 8-10 Types of Bindings 8-11 Generated Files in the View Project 8-12 Examining the DataBindings.cpx File 8-13 ADF Binding 8-14 Objects and Metadata Files 8-15 Opening a Page Definition File 8-16 Editing a Page Definition File 8-17 Editing Bindings 8-18 Expression Language (EL) and Bindings 8-19 Accessing Bindings Programmatically 8-20 Accessing Data Controls Programmatically 8-21 Understanding the Bindings On a Page 8-22 Search Page Bindings 8-23 Drag-and-Drop Usability 8-26 ADF Binding: Summary 8-27 Summary 8-28 Practice Overview: Using Databinding 8-29 Enhancing the Web Tier with ADF Faces Components Objectives 9-2 ADF Faces: Overview 9-3 What ADF Faces Brings to JSF 9-4 Key Terms 9-5 Components 9-6 Rendering and Behavior 9-7 ADF Faces Components: Examples 9-8 ADF Faces Components 9-9 Data Components 9-10 Input Components 9-11 Layout Components 9-12
viii

Navigational Components 9-14 Output Components 9-15 Facets 9-16 Custom Configuration Files and Libraries 9-18 ADF Faces Client-Side Validation 9-19 Look and Feel Customization 9-20 ADF Faces Skins 9-21 Debugging 9-22 ADF Faces: Consistent Programming Model 9-23 Multiclient Development 9-24 Conditional Rendering 9-25 Partial Page Rendering 9-26 Summary 9-27 Practice Overview: Using ADF Faces Components 9-28 10 Planning Navigation and Page Flow Objectives 10-2 Traditional Navigation 10-3 What Is JSF Navigation? 10-4 JSF Navigation: Example 10-5 JSF Navigation Rules 10-6 faces-config Console 10-8 faces-config.xml 10-9 JSF Navigation Modeler 10-10 JSF Navigation Diagram 10-11 Navigation Elements 10-12 Global Rules 10-14 Pattern-Based Rules 10-15 JSF: Example 10-16 JSF Navigation: Example 10-18 Using the JSF Configuration Editor 10-21 Managed Beans 10-22 Creating Managed Beans 10-24 Managed Bean: Example 10-25 Setting Managed Bean Scope 10-26 Relationships Between Managed Beans 10-27 Managed Properties 10-28 Managed Properties: Examples 10-29 Using the Managed Bean in the JSF Page 10-31 Summary 10-32 Practice Overview: Developing JSF Applications 10-33
ix

11 Enhancing the Applications Usability Objectives 11-2 Internationalization 11-3 Resource Bundles 11-4 Internationalizing an Application 11-6 Using Resource Bundles 11-7 Handling Error Messages 11-8 Control Hints and Validation 11-10 Using Control Hints 11-11 Accessing Control Hints 11-12 Control Hint Properties 11-13 ADF Declarative Validation 11-15 Adding Validation 11-16 Internationalizing Control Hints 11-17 Internationalizing the Message Bundle (Control Hints) 11-18 Internationalizing the Message Bundle (Control Hints): Example 11-19 Internationalizing the Message Bundle (Control Hints) 11-20 Internationalized Error Messages 11-21 Summary 11-22 Practice Overview: Internationalizing an Application 11-23 12 Building a Query Page Objectives 12-2 The Search Page 12-3 Using a Parameterized Named Query 12-4 Defining Parameters for Named Queries 12-5 The Query Expression 12-6 Moving the Named Query Forward 12-7 Adding the Named Query to the Session Facade 12-8 Re-Creating the Data Control 12-9 Building a Parameterized Form 12-10 Defining Display Properties of Parameters 12-11 Elements of an ADF Parameter Form 12-12 Using the Expression Language Editor 12-13 Editing Bindings 12-14 Binding a Button or Link to a Method 12-15 Working with the Binding 12-16 Using the Return to Display the Results 12-17 Display the Results 12-18 Using EL to Customize Search Results 12-19
x

Setting a Refresh Condition 12-20 Summary 12-22 Practice Overview: Creating a Search Form 12-23 13 Creating Updatable Pages Objectives 13-2 Using Components That Facilitate Data Entry 13-3 Using Methods on Pages 13-4 Executing Methods in ADF 13-5 Executing Bound Methods on JSF Page Load 13-6 Constructors 13-7 Transactional Methods 13-8 mergeEntity() 13-9 persistEntity() 13-10 Using Transactional Methods 13-11 Building an Insert Form 13-12 Displaying the Results 13-15 Using Backing Beans 13-16 Backing Bean: Example 13-17 Creating Backing Beans 13-18 Creating Managed Beans by Binding a Command Button 13-20 ADF Binding 13-21 Configuring ADF Binding Access for Managed Beans 13-22 Summary 13-23 Practice Overview: Completing the Edit Page 13-24 14 Handling Application Events Objectives 14-2 JSF Event Model 14-3 Types of Events 14-4 Action Events 14-5 Creating Action Events 14-6 Value Change Events 14-7 Creating Value Change Events 14-8 Event Listener Classes 14-9 Handling Action Events 14-10 Handling Value Change Events 14-11 Event and Listener Execution Order 14-12 Validation in the JSF Life Cycle 14-13 Entity Validation in the Commit Cycle 14-15 Handling Validation Exceptions 14-16
xi

Creating Custom Exception Handlers 14-17 Changing Life Cycle Exception Reporting 14-19 Customizing Page Exception Handling 14-20 JavaServer Faces Validators 14-21 ADF Binding Validation 14-22 Additional ADF Faces Validators 14-23 Creating Backing Bean Validation in JDeveloper 14-24 Backing Bean Validator: Code Example 14-25 Input Validation 14-26 Summary 14-27 Practice Overview: Wiring the Application Together 14-28 15 Deploying Java EE Applications Objectives 15-2 Java EE Server 15-3 Java EE Application Assembly and Deployment 15-5 Planning the Deployment Process 15-6 Deployment Containers 15-8 Packaging Java EE Application Components 15-9 JARs 15-10 WARs 15-11 EJB JARs 15-12 The EJB Deployment Process 15-13 EARs 15-14 EAR File Structure for a Java EE Application: Example 15-15 Working with Deployment Descriptors 15-16 JSR-88 Deployment Plans 15-17 Creating a JSR-88 Deployment Plan 15-18 Working with JSR-88 Deployment Plans 15-19 Oracle Application Server Containers for Java EE (OC4J) 15-20 OC4J Architecture 15-21 OC4J Server Configuration Files 15-22 Relation of Configuration Files 15-23 Application Logging 15-24 Data Sources 15-25 Data Source Definition 15-26 data-sources.xml: Example 15-27 Deploying an Application: Web Tier 15-28 Example: Creating a Web Deployment Profile 15-29 Deploying an Application: EJB Tier 15-30 Example: Creating an EJB Deployment Profile 15-31
xii

Deploying an Application: EAR File 15-32 Example: Creating the Application Deployment Profile 15-33 Example: Creating the Application Deployment Descriptor 15-34 Java EE Application Deployment to Oracle Application Server 10g 15-35 Deploying with JSR-88 Ant Tasks 15-36 Oracle Enterprise Manager 15-37 Deploying with Application Server Control 15-38 Summary 15-39 Practice Overview: Deploying Java EE Applications 15-40 16 Communicating Between Application Components Objectives 16-2 Communications: Overview 16-3 Messaging Systems: Overview 16-4 Synchronous and Asynchronous 16-5 Messaging in Action 16-6 Messaging Systems 16-7 Two Domains for JMS 16-8 Java Message Service 16-9 Message-Oriented Middleware and Queuing 16-10 Architecture of a JMS Application 16-11 Point-To-Point Model 16-12 Publish-And-Subscribe Model 16-13 JMS Connector Architecture in OC4J 10g 16-14 Life Cycle of a Message-Driven Bean 16-15 Using JMS Interfaces 16-16 Setting Up the JMS Messaging Service 16-17 Sending a Message to a Queue 16-18 Receiving Messages 16-20 Asynchronous Message Delivery 16-21 Message-Driven Beans 16-22 MDB Architecture 16-23 Anatomy of a Message Bean 16-24 Using Properties to Send Information 16-25 Creating a JMS/MDB Client 16-26 Summary 16-27 Practice Overview: Using a Message Bean 16-28

xiii

17 Developing the Business Tier with Web Services Objectives 17-2 What Is Service-Oriented Architecture (SOA)? 17-3 SOA: Development Life Cycle 17-4 What Is a Web Service? 17-5 Benefits of Web Services 17-7 Web Services and SOA 17-9 Web Services Model 17-10 Anatomy of a Service 17-11 Defining Web Services 17-12 Basic Web Services 17-13 Two Development Use Cases 17-14 JAX-RPC 17-15 Simple Object Access Protocol (SOAP) 17-16 Web Services Definition Language (WSDL) 17-17 Anatomy of a WSDL Document 17-20 Other Web Service Features 17-21 Using Http Analyzer 17-22 Why Web Services and Applications? 17-23 UDDI Registry 17-24 Options for Located Web Service 17-26 UDDI Publishing and Browsing with Oracle Enterprise Manager 17-27 Oracle Application Server 10g Web Services 17-28 Developing a Web Service with a Stateless Java Class 17-29 Defining an Interface 17-30 Defining a Stateless Java Class 17-31 Creating the Web Service 17-33 Examining the Web Service Files 17-34 Deploying the Web Service 17-35 Web Service Home Page 17-36 Testing the Deployed Web Service with Home Page 17-37 Testing the sayHello Operation 17-38 Exposing and Publishing a PL/SQL Package as a Web Service 17-39 Summary 17-40 Practice Overview: Creating a Web Service 17-41 18 Creating the Persistence Layer with TopLink Objectives 18-2 What Is TopLink? 18-3 Benefits of TopLink 18-4 Where Does TopLink Fit? 18-5
xiv

TopLink Objects 18-6 Extensions to JPA 18-7 TopLink Design Time 18-8 TopLink Mapping Editor 18-9 Mapping Types 18-10 TopLink Caching 18-11 Transaction Features and Support 18-12 Performance and Tuning Options 18-13 TopLink JAXB 18-14 Creating a TopLink Persistence Layer 18-15 Creating TopLink Objects 18-16 What Is a Named Query? 18-18 Building Named Queries 18-19 Query Editor 18-20 Adding Queries Using the Mapping Editor 18-21 Creating a Java Console Test Client 18-22 The Test Client 18-23 Building Query Objects in Code 18-24 Expressions 18-25 TopLink Support for Query Expressions 18-26 Query Object: Example 18-27 Using Sequences 18-28 TopLink Sessions 18-29 Role of the Session 18-30 POJO-Based Session Facade Methods 18-31 Unit of Work 18-32 Unit of Work: Life Cycle 18-34 Unit of Work: Example 18-35 ADF Model Databinding and TopLink 18-36 Data Control Palette 18-37 Creating a TopLink Data Control 18-38 Bindings 18-39 Summary 18-40 Practice Overview: Creating a TopLink Persistence Layer 18-41 19 Troubleshooting Objectives 19-2 Troubleshooting Basics 19-3 Diagnosing the Problem 19-4 Requesting Help 19-5 Creating Test Cases 19-6
xv

Logging and Diagnostics 19-7 Java Logging 19-8 Configuring Java Logging 19-9 Sending Logger Output to a File 19-10 ADF Logger 19-11 Using ADF Diagnostics 19-12 Turning on Diagnostics in JDeveloper 19-13 Turning on Diagnostics in OC4J 19-14 Sample Java Clients 19-15 Sample Client for Web Service 19-16 Tools and Utilities 19-17 Identifying Search Paths with FileMon 19-18 Testing Java Code with JUnit 19-19 Analyzing HTTP Requests 19-20 Debugging with JDeveloper 19-21 Summary 19-23 Appendix A: Practice and Solutions

xvi

Potrebbero piacerti anche