• Introduction to JBoss Seam


  •   
  • FileName: IntroductionJBossSeam.pdf [read-online]
    • Abstract: Introduction to JBoss SeamJava and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. License for use and distributionThis material is available for non-commercial

Download the ebook

Introduction to JBoss Seam
Java and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
License for use and distribution
This material is available for non-commercial
use and can be derived and/or redistributed, as
long as it uses an equivalent license.
Attribution-Noncommercial-
Share Alike 3.0 Unported
http://creativecommons.org/licenses/by-nc-sa/3.0/
You are free to share and to adapt this work under the following conditions:
(a) You must attribute the work in the manner specified by the author or
licensor (but not in any way that suggests that they endorse you or your use
of the work); (b) You may not use this work for commercial purposes. (c) If
you alter, transform, or build upon this work, you may distribute the
resulting work only under the same or similar license to this one.
2
November 2007 Introduction to JBoss Seam
About the author – Vítor Souza
Education:
Computer Science graduate, masters in Software
Engineering – Federal University of Espírito Santo (Brazil).
Java:
Developer since 1999;
Focus on Web Development;
Co-founder and coordinator of ESJUG (Brazil).
Professional:
Substitute teacher at Federal University of ES;
Engenho de Software Consulting & Development.
Contact: [email protected] 3
November 2007 Introduction to JBoss Seam
Summary
Introduction;
JBoss Seam overview;
A simple application with JBoss Seam;
Features to explore...
4
November 2007 Introduction to JBoss Seam
Technology timeline
Servlets JDBC
JSP EJB 2
MVC ORM
JSF JBoss Seam EJB 3
5
November 2007 Introduction to JBoss Seam
JavaServer Faces
Similarities with the MVC frameworks;
Focus on the developer;
Designed to be used by IDEs;
Extensible UI components;
Event handling;
Simple navigation support.
6
November 2007 Introduction to JBoss Seam
EJB 3.0
Part of the Java Enterprise architecture:
Security, life cycle management, remote accessibility,
persistence, transaction handling, concurrency,
clustering, etc.
Simplified model;
Less XML and more annotations;
Entity Beans can be replaced by ORM;
JNDI can be replaced by DI.
7
November 2007 Introduction to JBoss Seam
JBoss Seam
Ideas taken from MVC frameworks, ORM and DI
were included in the Java EE 5 “package”;
Why another framework?
The piece that is missing in the “package”:
JSF and EJB3: different philosophies;
Replaces backing beans and the integration plumbing;
Use of annotations and contextual components;
Many extra features;
Productivity with scalability.
8
November 2007 Introduction to JBoss Seam
JBoss Seam
General information:
Created by Gavin King (creator of Hibernate);
Version 1.0 released in 11/06/2006;
Current version: 2.0;
Websites:
http://www.jboss.com/products/seam
http://labs.jboss.com/jbossseam/gettingstarted
http://labs.jboss.com/jbossseam/download/index.html
9
November 2007 Introduction to JBoss Seam
Overview
JSF – EJB3 integration;
Integrated AJAX and jBPM;
Uniform component model;
Declarative state management;
Bijection;
Workspace management;
Use of annotated POJOs;
Testability.
10
November 2007 Introduction to JBoss Seam
Seaming things...
Source: Seam Reference
11
November 2007 Introduction to JBoss Seam
JBoss Seam
A simple example
12
November 2007 Introduction to JBoss Seam
Demonstration
Tools:
JBoss 4.2.1 GA (EJB 3 support);
JBoss Seam 2.0.0 GA;
Eclipse Europa (3.3.1.1) with Java EE support;
ICEFaces 1.6.0.
Goal:
Build a contact list with two simple functionalities:
Add contact;
View contact.
13
November 2007 Introduction to JBoss Seam
System architecture
14
November 2007 Introduction to JBoss Seam
A Seam project on Eclipse
Create an Enterprise Application Project:
EJB module: persistence, domain and application;
Web module: controller and view;
Client and Connector modules: not used.
Very specific configuration:
It's easier to start from one of Seam's examples;
You can also use seam-gen.
15
November 2007 Introduction to JBoss Seam
The enterprise application project
EarContent/
META-INF/
application.xml
contactlist-ds.xml
jboss-app.xml
lib/
hsqldb-1.8.jar You will need to adapt
this if using another
jboss-el-2.0.jar
application server
seam-2.0.jar
hsqldb/
16
November 2007 Introduction to JBoss Seam
application.xml

ContactList

ContactListEJB.jar



ContactListWeb.war
ContactListWeb



seam-2.0.jar


The JARs under lib/ will be automatically added by JBoss!
17
November 2007 Introduction to JBoss Seam
jboss-app.xml


seam.jboss.org:loader=ContactList


META-INF/contactlist-ds.xml


18
November 2007 Introduction to JBoss Seam
contactlist-ds.xml


ContactListDataSource

jdbc:hsqldb:hsql://localhost/contactlist

org.hsqldb.jdbcDriver
sa

5
20
0

Hypersonic SQL



19
November 2007 Introduction to JBoss Seam
The EJB project
ejbModule/
net.java.dev.esjug.util.* (utilities)
META-INF/
ejb-jar.xml
persistence.xml
seam.properties (empty)
20
November 2007 Introduction to JBoss Seam
ejb-jar.xml




org.jboss.seam.ejb.SeamInterceptor





*

org.jboss.seam.ejb.SeamInterceptor



21
November 2007 Introduction to JBoss Seam
persistence.xml



org.hibernate.ejb.HibernatePersistence


java:/ContactListDataSource






22

November 2007 Introduction to JBoss Seam
Domain object support
@MappedSuperclass
public abstract class DomainObjectSupport
implements DomainObject {
@Column(nullable = false, length = 40)
private String uuid; // + getter/setter
public DomainObjectSupport() {
uuid = UUID.randomUUID().toString();
}
public boolean equals(Object o) {
if (! getClass().equals(o.getClass())) return false;
DomainObjectSupport obj = (DomainObjectSupport)o;
return uuid.equals(obj.uuid);
}
public int hashCode() {
return uuid.hashCode();
}
}
23
November 2007 Introduction to JBoss Seam
Persistent object support
@MappedSuperclass
public abstract class PersistentObjectSupport extends
DomainObjectSupport implements PersistentObject
{
@Id @GeneratedValue(strategy = GenerationType.AUTO)
private I id;
@Version @Column(nullable = false)
private V version;
public boolean isPersistent() {
return (id != null);
}
}
24
November 2007 Introduction to JBoss Seam
Seam DAO support
public abstract class SeamBaseDAO


javax.faces.STATE_SAVING_METHOD
server

33
November 2007 Introduction to JBoss Seam
web.xml


javax.faces.DEFAULT_SUFFIX
.xhtml


Faces Servlet

javax.faces.webapp.FacesServlet

1



facelets.DEVELOPMENT
true
34
November 2007 Introduction to JBoss Seam
web.xml


com.icesoft.faces.util.event
.servlet.ContextEventRepeater



com.icesoft.faces.actionURLSuffix

.seam



com.icesoft.faces.synchronousUpdate

false

35
November 2007 Introduction to JBoss Seam
web.xml


com.icesoft.faces.doJSFStateManagement

true



com.icesoft.faces.standardRequestScope

true

36
November 2007 Introduction to JBoss Seam
web.xml

Persistent Servlet

com.icesoft.faces.webapp
.xmlhttp.PersistentFacesServlet

1


Persistent Servlet
*.seam


Persistent Servlet
/xmlhttp/*

37
November 2007 Introduction to JBoss Seam
web.xml

Blocking Servlet

com.icesoft.faces.webapp.xmlhttp.BlockingServlet

1


Blocking Servlet
/block/*



10

38
November 2007 Introduction to JBoss Seam
web.xml


index.jsp

39
November 2007 Introduction to JBoss Seam
Seam components to develop
Entities (domain classes);
DAOs (persistence classes);
Services (application classes);
Action (controller classes);
Web pages (view).
40
November 2007 Introduction to JBoss Seam
Creating an entity
@Entity
public class Contact extends
PersistentObjectSupport implements
Comparable {
@Column(length = 50)
private String name;
@Temporal(TemporalType.DATE)
private Date birthDate;
@OneToMany(cascade = CascadeType.ALL)
@Sort(type = SortType.NATURAL)
private SortedSet contactInfo;
...
}
41
Agosto 2007 Introdução ao JBoss Seam
Creating a DAO
@AutoCreate
@Name("contactDAO")
@Scope(ScopeType.APPLICATION)
@Stateless
public class SeamContactDAO extends
SeamBaseDAO implements ContactDAO {
@PersistenceContext
private EntityManager entityManager;
...
}
42
Agosto 2007 Introdução ao JBoss Seam
Creating a service
@Local
public interface ManageAddressBookService { ... }
@AutoCreate
@Name("manageAddressBookService")
@Scope(ScopeType.APPLICATION)
@Stateless
public class ManageAddressBookServiceBean implements
ManageAddressBookService {
@In
private ContactDAO contactDAO;
...
}
43
November 2007 Introduction to JBoss Seam
Creating an action
@Name("manageAddressBookAction")
@Scope(ScopeType.SESSION)
public class ManageAddressBookAction {
@In
private ManageAddressBookService
manageAddressBookService;
private SortedSet contactList;
private Contact contact = new Contact();
...
44
November 2007 Introduction to JBoss Seam
Creating an action
public void addContact() {
log.info("Adding contact: #0, #1, #2, #3, #4",
contact.getId(), contact.getName(),
contact.getBirthDate(), information.getType(),
information.getValue());
Contact c =
manageAddressBookService.addContact(contact,
information);
getContactList().add(c);
FacesMessages.instance().add("#{messages['text.succes
sFullyAddedContact']}", contact.getName());
contact = new Contact();
information = new ContactInformation();
}
}
45
November 2007 Introduction to JBoss Seam
Referring to the action on web pages


...



...
46
November 2007 Introduction to JBoss Seam
JBoss Seam
Features to experiment
47
November 2007 Introduction to JBoss Seam
Internationalization
48
November 2007 Introduction to JBoss Seam
Pageflow
49
November 2007 Introduction to JBoss Seam
Conversation and workspace
50
November 2007 Introduction to JBoss Seam
Authentication
51
November 2007 Introduction to JBoss Seam
Debugging
52
November 2007 Introduction to JBoss Seam
RESTful URLs
53
November 2007 Introduction to JBoss Seam
seam-gen
54
November 2007 Introduction to JBoss Seam
Contexts
Stateless;
Event (or request);
Page;
Conversation;
Session;
Business Process;
Application.
55
November 2007 Introduction to JBoss Seam
Bijection
56
November 2007 Introduction to JBoss Seam
Events
57
November 2007 Introduction to JBoss Seam
Interceptors
58
November 2007 Introduction to JBoss Seam
Exception handling
59
November 2007 Introduction to JBoss Seam
New on Seam 2.0
Web services can be Seam-aware;
Seam components can be written in Groovy;
Hot deploy;
Eclipse support (JBossTools & RH Dev Studio);
De-coupled from JSF;
JBoss EL;
Maven repository;
Integration to Quartz and JFreeChart;
Improved support for non-EE environments.
60
November 2007 Introduction to JBoss Seam
Introduction to JBoss Seam
Java and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries.


Use: 0.274