Java EE WebApplication with JDeveloper 10 g R
Java EE Web-Application with JDeveloper 10 g. R 3 1 -1 • EJB 3. 0 • Databinding • Java Server Faces – ADF-Faces Copyright © 2006, Oracle. All rights reserved.
Java EE Platform • • • 1 -2 Is a multitiered, distributed application model Supports component-based Java EE applications Distributes the application logic to the appropriate tier on the multitiered architecture Copyright © 2006, Oracle. All rights reserved.
Distributed Multitiered Applications Java EE Application 1 Java EE Application 2 Client Tier Application Client Dynamic HTML Pages JSP Pages Enterprise Beans Web Tier Java EE Server Business Tier EIS Tier 1 -3 Client Machine Copyright © 2006, Oracle. All rights reserved. Database Server
Java EE Architecture Java EE Server Browser Application Client Container Client Machine Web Container Java Servlet/JSF EJB Business services container APIs JNDI JTA JMS RMI JDBC JAF Java. Mail 1 -4 Copyright © 2006, Oracle. All rights reserved. Database
Benefits of the Java EE Platform • • • 1 -5 “Write once, run anywhere” provides simplified component development. Multiple server products and vendors support the Java EE standard, thus giving more deployment choices. Java EE separates client requirements from business logic. It provides multiple development and design scenarios. It allows multiple clients to share server business logic. Copyright © 2006, Oracle. All rights reserved.
Benefits of the Java EE Platform Java EE separates development tasks into specific skill areas: • Web designers can create JSF components. • Java programmers and business experts create business logic and rules. • Production environment teams can handle assembly and deployment. 1 -6 Copyright © 2006, Oracle. All rights reserved.
Java EE Components • • • Java EE applications are made up of components. A component is an application-level software unit. Components can be easily updated as business needs change. Components are reusable. There are several types of components: – Client-side components – Web components – Business-tier components 1 -7 Copyright © 2006, Oracle. All rights reserved.
Java EE 5. 0 Components The Java EE 5. 0 Specification lists the following components: • Java Message Service API • Java Servlet 2. 5 • Java Transaction API • Java. Server Pages 2. 1 • Java Persistence API • Enterprise Java. Beans 3. 0 • J 2 EE Connector Architecture 1. 5 • Java API for XML-Based Web Services 2. 0 • SOAP with Attachments API for Java (SAAJ) • Java API for XML-Based RPC 1. 1 • Streaming API for XML • Web Service Metadata for the Java Platform 1 -8 Copyright © 2006, Oracle. All rights reserved.
Enterprise Java. Beans (EJB) Enterprise Java. Beans: • Are server-side components written in Java • Contain the business logic of an enterprise application • Are hosted in EJB containers • Are based on Remote Method Invocation (RMI) communication • Are platform independent • Provide remote services for clients • Can be exposed as Web services • Use JDBC to connect to a database 1 -9 Copyright © 2006, Oracle. All rights reserved.
Types of EJB • Entity bean – Used to model the persistence part of an application • Session bean – Invoked by a client to perform a specific business operation • Message-driven bean – Triggered by messages sent to a messaging server which enables sending asynchronous messages between system components 1 -10 Copyright © 2006, Oracle. All rights reserved.
The Java Persistence API (JPA) deals with: • The way relational data is mapped to Java objects (“persistent entities”) • The way these objects are stored in a relational database so that they can be accessed at a later time • The continued existence of an entity’s state even after the application that uses it, ends 1 -11 Copyright © 2006, Oracle. All rights reserved.
Java EE Web-Tier Components • A Web tier may consist of: – Java servlets – JSPs • Servlets and JSPs: – – – Work on a request-response model Generate HTML dynamically Access the database through JDBC Access the business-tier components Handle user-centric events, such as an HREF link or form submission – Usually generate visual interfaces such as a Web page 1 -12 Copyright © 2006, Oracle. All rights reserved.
What Is a Servlet? Servlet Browser Client info (host name, form data) Request Process results (access database) Format results and produce HTML Success or failure Send page back to client Response 1 -14 Copyright © 2006, Oracle. All rights reserved.
What Is a Java. Server Page (JSP)? A JSP: • Is a text-based document that includes: – HTML – JSP tags – Java code (including calls to Java. Beans and servlets) • • • 1 -15 Cleanly separates content creation from presentation logic Focuses on rapid development and easy modification of the user interface Focuses on presentation Copyright © 2006, Oracle. All rights reserved.
What Is Java. Server Faces (JSF)? JSF: • Is a server-side component framework for Web applications • Implements the Model-View-Controller (MVC) framework • Provides separation of navigational and data flow • Built for RAD style development 1 -16 Copyright © 2006, Oracle. All rights reserved.
JSF: Overview Java. Server Faces (JSF) provides the same benefits as the Struts architecture, including: • Controller servlet (MVC implementation) • Declarative and visual design in JDeveloper • XML configuration file (faces-config. xml) 1 -17 Copyright © 2006, Oracle. All rights reserved.
Web-Tier Components: Summary • • Web-tier components generate dynamic content. Servlets: – Extend Web server functionality – Are best used for business logic • JSPs: – Combine HTML (or other markup) and Java – Are best used for presentation logic • JSFs: – Are component based – Implement MVC 1 -18 Copyright © 2006, Oracle. All rights reserved.
Client-Tier Components • A Web browser: – Is used for a Web-based Java EE application – Downloads static or dynamic Web pages from Web-tier components – Is a thin client • An application client: – Is used for a non-browser-based Java EE application – Executes on the client machine – Can contain a graphical or command-line interface – Is a thick client – Accesses middle-tier services – Requires installation on the client machine 1 -19 Copyright © 2006, Oracle. All rights reserved.
What Is Persistence? The persistence layer provides mapping between objects and database tables. This layer: • Enables portability across databases and schemas • Supports read and write capabilities • Protects developers from database issues • Should be used in any application that has an object model 1 -21 Copyright © 2006, Oracle. All rights reserved.
Persistence: Overview • • Mapping relational database objects to Java objects enables easy Java EE application development. Frameworks such as EJB 3. 0 JPA provide this object-relational mapping. Entity/JPA Persistence Architecture Java model 1 -22 Schema Copyright © 2006, Oracle. All rights reserved.
JPA Entities • Consistent persistence mechanism – Java Persistence API (JPA) • Simple programming model – – • POJO persistence (Plain Old Java Interface) Object-Relational mapping annotations Getter/setter methods Can contain logic (validation and so on) The Entity. Manager object – Handles data manipulation – Enables entities to be called outside the container 1 -23 Copyright © 2006, Oracle. All rights reserved.
Entity Annotations • @Entity – @Id. Class – @Embedded. Id • @Table, @Seconday. Table – @Unique. Constraint – @Primary. Key. Join. Column(s) • • @Named. Query(s) Sequencing – @Generated. Value – @Sequence. Generator – @Table. Generator 1 -24 Copyright © 2006, Oracle. All rights reserved.
How Do JPA Entities Work? A JPA entity: • Is a lightweight object that manages persistence data • Is defined as a Plain Old Java Object (POJO) marked with the Entity annotation (no interfaces required) • Must implement the java. io. Serializable interface to be passed by value to a remote application • Is mapped to a database by using annotations @Entity @Table(name=“PRODUCTS") @Id @Column(name=“PRODID") POJO ORDERS Database 1 -25 Copyright © 2006, Oracle. All rights reserved.
Mapping Relationships Between Entities Annotations for entity relationships: • One. To. One User 1 -26 • One. To. Many • Many. To. Many and Association. Table Address Service. Request Service. History Users Copyright © 2006, Oracle. All rights reserved. Products
Writing Basic JPA QL SELECT Statements • Syntax for a JPA QL SELECT statement: SELECT [DISTINCT] select_expression FROM abstract_schema_name [AS] identifier_variable [WHERE conditional_expressions(s)] [ORDER BY order_by_item(s)] • JPA QL Named Query example: – Find all Products. @Named. Query(name = "Products. find. All", query = "select o from Products o"), 1 -27 Copyright © 2006, Oracle. All rights reserved.
What Is a Session Bean? A session bean is a type of Enterprise Java. Bean (EJB) that: • Implements a business process • Represents a client/server interaction • Has a short lifespan • Lives in memory rather than in persistent storage • Is used to create a session facade 1 -28 Copyright © 2006, Oracle. All rights reserved.
Stateless Versus Stateful Session Beans There are two types of session beans: • Stateless session bean (SLSB) – Conversation is contained in a single method call. – Business process does not maintain client state. • Stateful session bean (SFSB) – Conversation may invoke many methods. – Business processes can span multiple method requests, which may require maintaining state. EJB container Pool of SLSBs 1 -29 EJB container SFSBs Client 1 Client 2 Copyright © 2006, Oracle. All rights reserved.
Elements of a Stateless Session Bean A stateless session bean contains: • Business interfaces, which contain the business method definition • A bean class, which implements the business JVM method @Remote String say. Hello() Remote client @Stateless String say. Hello() { return "Hello"; } @Local String say. Hello() Local client 1 -30 Interfaces Bean class Copyright © 2006, Oracle. All rights reserved.
ADF Architecture ADF Swing ADF Faces JSP JSF ADF Controller Struts Controller JSF Model ADF Model XML 1 -31 Web Services EJB + Top. Link ADF Business Components View Java. Beans Copyright © 2006, Oracle. All rights reserved. Business Services
Model Layer Components • • • Data controls describe the public interface of a business service. Bindings connect UI components to data or actions. Data controls and bindings are defined using XML metadata. Bindings Data control Business service 1 -32 Copyright © 2006, Oracle. All rights reserved.
JSF Components consists of three parts: • UI components: Functionality, attributes, or behavior • Renderers: Converts components to and from a specific markup language • Render kits: Library of renderers (Basic HTML Render. Kit is part of the specification. ) 1 -33 Copyright © 2006, Oracle. All rights reserved.
JSF UI Components • • • 1 -34 Are the basic building blocks of a JSF application Are stateful server objects Do not define rendering Can represent simple to complex user interface components ranging from a button or input field to a complete page Can be associated to model data objects through value binding Can use helper objects such as validators, converters, listeners, and events Copyright © 2006, Oracle. All rights reserved.
JSF Architecture HTML render kit HTML browser Front controller Phone/ PDA 1 -35 Page Backend code WML render kit Page Copyright © 2006, Oracle. All rights reserved.
Managed Beans • Managed beans can: – Store state – Execute a Java routine – Define a handler for event listeners • • They have no-argument constructors. Lazy initialization is performed by Java. Server Faces. Access scope: None, Request, Application, or Session Backing beans: – Are special types of managed beans – Contain getter and setter methods for UI components 1 -36 Copyright © 2006, Oracle. All rights reserved.
Expression Language 1 -37 • Dot notation for attributes (Java. Bean model): #{userbean. name} same as instance. get. Name(); • Map notation: #{foo["baa"]} same as instance. get("baa"); • Expressions can be of any depth: #{foo["baa"]. person. name} • Expressions can evaluate: #{userbean. name} same as foo["baa"]. person. name} true|false Copyright © 2006, Oracle. All rights reserved.
JSF Navigation Diagram 1 -38 Copyright © 2006, Oracle. All rights reserved.
- Slides: 36