0% found this document useful (0 votes)
29 views

Java EE Components: Jpa, Ejb, JSF

Java EE components include applets, applications, web applications, and enterprise Java beans. Web applications are made up of servlets, filters, listeners, JSP pages, and JSF components. The model-view-controller pattern separates an application's data model from the user interface, with the controller mediating interactions between the two.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Java EE Components: Jpa, Ejb, JSF

Java EE components include applets, applications, web applications, and enterprise Java beans. Web applications are made up of servlets, filters, listeners, JSP pages, and JSF components. The model-view-controller pattern separates an application's data model from the user interface, with the controller mediating interactions between the two.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Java EE Components

• Applets: GUI app’s executed in a web browser. They use the


Swing API to provide powerful user interfaces.
• Applications: programs executed on a client. Typically GUIs or
batch-processing programs that have access to all the facilities of
Java EE: An Introduction the Java EE middle tier.
• Web applications: app’s executed in a web container and respond
JPA, EJB, JSF to HTTP requests from web clients.
• Made of servlets, servlet filters, web event listeners, JSP pages,
and JSF. Servlets also support web service endpoints
• Enterprise Java Beans: container-managed components for
processing transactional business logic. They can be accessed
locally and remotely through RMI (or HTTP for SOAP and
RESTful web services).
Wednesday, January 27, 2010 1 Wednesday, January 27, 2010 2

MVC Design Pattern JEE app and the MVC architecture


• In a JEE application:
• The Model-View-Controller
(MVC) design pattern separates • The model -- business layer functionality represented by JavaBeans or
EJBs
the core business model
functionality from the • The view -- the presentation layer functionality represented by JSFs
presentation and control logic (the view)
that uses this functionality.
• The controller -- Servlet mediating between model and view
• The separation allows multiple
• Must accommodate input from various clients including
views to share the same
enterprise data model, which
HTTP requests from web clients, and…
makes supporting multiple • WML from wireless clients
clients easier to implement,
test, and maintain. • XML documents from suppliers
Source: Java BluePrints - J2EE Patterns, MVC • Etc.
http://java.sun.com/blueprints/patterns/MVC-detailed.html
Wednesday, January 27, 2010 3 Wednesday, January 27, 2010 4
Model layer in a Web App View layer in a Web App

• Models the data and behavior behind the business process


• What it’s responsible for:
• Display information according to client types
• Performing DB queries
• Display result of business logic (Model)
• Calculating the business process
• Not concerned with how the information was obtained, or
• Processing orders
from where (since that is the responsibility of Model)
• Encapsulation of data and behavior which are independent
of presentation

Wednesday, January 27, 2010 5 Wednesday, January 27, 2010 6

Controller in a Web App Web Applications

• A web application is a dynamic extension of a web or application


• Serves as the logical connection between the user's server. Types of web applications:
interaction and the business services on the back
• Presentation-oriented
• Responsible for making decisions among multiple • generates interactive web pages containing various types of markup language
presentations (HTML, XHTML, XML, and so on) and dynamic content in response to requests.

• e.g. User's language, locale or access level dictates a different • Service-oriented


presentation. • A service-oriented web application implements the endpoint of a web service.

• A request enters the application through the control layer, • In Java EE platform, web components provide the dynamic
which will decide how the request should be handled and extension capabilities for a web server.
what information should be returned • Web components are either Java servlets, web pages, web service
endpoints, or JSP pages

Wednesday, January 27, 2010 7 Wednesday, January 27, 2010 8


Java Web App Request Java EE Architecture
Handling • Java EE is a set of specifications
implemented by different
containers.

• Containers are Java EE runtime


environments that provide
DB
certain services to the
components they host such as
lifecycle management,
dependency injection, security,
etc.

• Figure shows the logical


DB relationships between
containers. The arrows
From chapter 3 of The Java EE 6 Tutorial,
rial, http://java.sun.com/javaee/6/docs/tutorial/doc/geysj.html
represent the protocols used.
Wednesday, January 27, 2010 9 Wednesday, January 27, 2010 10

Servlets and JSF Java EE Services


• Servlets are Java classes that dynamically process requests • JPA: Standard API for object-relational mapping (ORM).
and construct responses. Includes JPQL to query objects stored in the underlying
database.
• JavaServer Faces and Facelets are used for building
interactive web applications. • JMS: allows components to communicate asynchronously
through messages.
• Servlets are best suited for service-oriented applications
(web service endpoints are implemented as servlets) and the • Java Naming and Directory Interface (JNDI): used to access
control functions of a presentation-oriented application, naming and directory systems.
such as dispatching requests and handling nontextual data. • JTA: a transaction demarcation API
• Java Server Faces and Facelets pages are more appropriate • JavaMail, JavaBeans Activation Framework (JAF), XML
for generating text-based markup, such as XHTML, and are processing, JCA, JAAS, RESTful web services,
generally used for presentation–oriented applications. Management, Deployment.
Wednesday, January 27, 2010 11 Wednesday, January 27, 2010 12
JPA JPA
• Objects vs. Entities
• Relational model (i.e. RDBMS) vs. Object Oriented model
• Objects are instances that just @Entity
(i.e. Java) live in memory.
public class Book {

@Id @GeneratedValue
• Object-Relational Mapping (ORM) • Entities are objects that live private Long id;
shortly in memory and
• Java Persistence API (JPA) persistently in a database.
@Column(nullable = false)
private String title;
private Float price;
• An API above JDBC
• JPA map objects to a database via @Column(length = 2000)
private String description;
• Can access and manipulate relational data from Enterprise Java metadata that can be supplied private String isbn;
Beans (EJBs), web components, and Java SE applications using annotations or in an XML private Integer nbOfPage;
private Boolean illustrations;
descriptor
• Includes an entity manager API to perform DB-related // Constructors, getters, setters
operations like CRUD • Annotations: The code of the }
entity is directly annotated with all
• Includes JPQL, an object-oriented query language sorts of annotations described in
the javax.persistence package.
Wednesday, January 27, 2010 13 Wednesday, January 27, 2010 14

Enterprise Java Beans


JPA mapping

• server-side components

• encapsulate business logic

• take care of transactions and security

• used in building business layers to sit on top


of the persistence layer and as an entry point
for presentation-tier technologies like
JavaServer Faces (JSF).

• can be built by annotating a POJO that will


be deployed into a container

Wednesday, January 27, 2010 15 Wednesday, January 27, 2010 16


Types of EJBs EJB Example
@Stateless
public class BookEJB {
• Session beans and Message-driven Beans (MDBs) @PersistenceContext(unitName = "chapter06PU")
private EntityManager em;
• Session Beans are used to encapsulate high-level business
logic and can be... public Book findBookById(Long id) {
return em.find(Book.class, id);
• Stateless: contains no conversational state between methods, and }
any instance can be used for any client
• Stateful: contains conversational state, which must be retained public Book createBook(Book book) {
across methods for a single user em.persist(book);

• Singleton: A single session bean is shared between clients and return book;
supports concurrent access }
}

Wednesday, January 27, 2010 17 Wednesday, January 27, 2010 18

Web pages and web servers JSF


• Web servers
• Handles HTTP requests and sends a HTTP response -- typically
HTML page
• Default HTTP port: 80 • JSF applications are
standard web
• Typical servers: Apache (47%), MS (21%) applications that
• Netcraft Web Server Survey (December 2009) intercept HTTP via
the Faces servlet and
• “Web languages” produce HTML
• HTML
• CSS
• JavaScript

Wednesday, January 27, 2010 19 Wednesday, January 27, 2010 20


<!DOCTYPE
YPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
" http://www.w3.org/TR/xhtml1/DTD/x
<html xmlns="
ns="
"http://www.w3.org/1999/xhtml"
http://www.w3.org/1999/xhtml Packaging Java EE Web Apps
xml
xmlns=
xmlns:h="
<h:head>
h="http://java.sun.com/jsf/html">
h="

<title>Creates a new book</title>


</h:head>
<h:body> • A web application module contains:
<h1>Create a new book</h1>
<hr/>
<h:form>
• servlets, JSPs, JSF pages, and web services,
<table border="0">
<tr> • as well as HTML and XHTML pages, Cascading Style Sheets
<td><h:outputLabel value="ISBN : "/> /></td>
/> (CSS), JavaScripts, images, videos, and so on.
<td><h:inputText value="#{bookController.book.isbn}"/></td>
</tr>
• All these artifacts are packaged in a jar file with a .war
<tr>
<td><h:outputLabel value="Title :"/></td>
extension -- i.e., a war file, or Web Archive.
<td><h:inputText value="#{bookController.book.title}"/></td>
</tr> • WEB-INF/web.xml is the optional web deployment descriptor
</table>

<h:commandButton value="Create a book" • WEB-INF/ejb-jar.xml is the optional EJB Lite beans


action="#{bookController.doCreateBook}" styleClass="submit"/> deployment descriptor.
</h:form>
<hr/> • WEB-INF/classes contains all the Java .class files
<i>APress - Beginning Java EE 6</i>
</h:body> • WEB-INF/lib contains any dependent jar files.
</html>
Wednesday, January 27, 2010 21 Wednesday, January 27, 2010 22

You might also like