SlideShare a Scribd company logo
Refactoring to Seam Brian Leonard Technology Evangelist Sun Microsystems, Inc.
AGENDA The Java EE 5 Programming Model Introduction to Seam Refactor to use the Seam Framework Seam Portability Q&A
Java EE 5 Programming Model Registration Application Managed Bean Entity Class
DEMO
Java EE 5 Programming Model JSF Context DB Registration Application Managed Bean JSF Components Action Class Entity Class RegisterActionBean User ManagedBean
register.jsp: JSF In Action <td> Username </td> <td> < h:inputText   id = &quot;userName&quot;   value = &quot; #{ user.username } &quot;   required = &quot;true&quot; > < f:validateLength   minimum = &quot;5&quot;   maximum = &quot;15 &quot; / > <td> Real Name </td> <td> < h:inputText   id = &quot;name&quot;   value = &quot; #{ user.name } &quot;   required = &quot;true&quot; > <td> Password </td> <td> < h:inputSecret   id = &quot;password&quot;   value = &quot; #{ user.password } &quot;   required = &quot;true&quot; > < f:validateLength   minimum = &quot;5&quot;   maximum = &quot;15 &quot; / >    < h:commandButton   id = &quot;registerCommand&quot;   type = &quot;submit&quot;   value = &quot;Register&quot;   action = &quot; #{ user.register } &quot; / > A JSF Validator
register.jsp & BackingBean ... <td> Username </td> <td> < h:inputText   id = &quot;userName&quot;   value = &quot; #{ user.username} &quot;   ... <td> Real Name </td> <td> < h:inputText   id = &quot;name&quot;   value = &quot; #{ user.name} &quot;   ... <td> Password </td> <td> < h:inputSecret   id = &quot;password&quot;   value = &quot; #{ user.password} &quot; ... < h:commandButton   id = &quot;registerCommand&quot;   type = &quot;submit&quot;   value = &quot;Register&quot;   action = &quot; #{ user.register} &quot; / > ... ManagedBean username name password register “ user”
Managed Beans Configuration  ... <managed-bean> < managed-bean-name > user </managed-bean-name> < managed-bean-class >  org.examples.jsf. ManagedBean </managed-bean-class> <managed-bean-scope> request </managed-bean-scope> </managed-bean> ... faces-config.xml <td> < h:inputText   id = &quot;userName&quot;   value = &quot; #{ user.username} &quot;
Managed Bean public class ManagedBean { private String  username ; private String  name ; private String  password ; public String getUsername() { return username; } Public String setUsernaame(String username) { this.username=username; } ... private RegisterActionLocal registerActionBean;  private InitialContext ctx; { try { ctx = new InitialContext(); registerActionBean = (RegisterActionLocal)    ctx.lookup(&quot;registration/RegisterActionBean/local&quot;); } catch (NamingException ex) { ex.printStackTrace(); } }  public String  register () { return registerActionBean.register(username, name, password); }
EJB 3.0 Dramatic simplification of all bean types Regular Java classes (POJO) @ Stateless,  @ Stateful,  @ MessageDriven Use standard interface inheritance Dependency injection Instead of JNDI Interceptors Entity Beans (CMP) replaced with JPA
Java Persistence API (JPA) Single persistence API for Java EE  AND  Java SE Much  simpler the EJB CMP At least three implementations (all open source): Hibernate (JBoss) TopLink Essentials (Oracle) Kodo/Open JPA (BEA) Configured via persistence.xml
JPA – Object Relational Mapping Developer works with objects Database queries return objects Object changes persist to the database Data transformation is handled by the persistence provider (Hibernate, Toplink, etc.) Annotations define how to map objects to tables @ Entity marks a regular java class as an entity Class atributes map to table columns Can be customized with  @ Column Manage relationships:  @ OneToMany
Our Entity Bean @Entity @Table(name=&quot;users&quot;)     public class User implements Serializable{ @Id  private String  username;  private String password; private String name; public User(String name, String password,  String username){ this.name = name; this.password = password; this.username = username; } //getters and setters...
JPA Entity Manager Entity Manger stores/retrieves data Inject Entity Manager: @PersistenceContext private EntityManager em; Create an instance of the entity: User u = new User(params); Use Entity Manager methods to persist data: em.persist(u); em.merge(u); em.delete(u); Query using EJB QL or SQL User u = em.find(User.class, param);
Our Action Bean @Stateless   public class RegisterAction implements Register{  @PersistenceContext   private EntityManager em; public String register(String username, String name,  String password){  List existing =  em.createQuery (&quot;select username  from User where username=:username&quot;) .setParameter(&quot;username&quot;, username ) .getResultList(); if (existing.size()==0){ // Create a new user User user = new User(username, name, password) em.persist(user) ; return  &quot;success&quot; ;  } else {  FacesContext facesContext =    FacesContext.getCurrentInstance(); FacesMessage message = new  FacesMessage(username + &quot; already exists&quot;); facesContext.addMessage(null, message); return null;  }}}
AGENDA The Java EE 5 Programming Model Introduction to Seam Refactor to use the Seam Framework Seam Portability Q&A
JBoss Seam Application Framework for integrating JSF and EJB 3 component models: Bridge web-tier and EJB tier session contexts Enable EJB 3.0 components to be used as JSF managed beans Integrated AjAX solutions from ICEfaces and Ajax4JSF Improved state management Prototype for JSR 299: Web Beans
JBoss Seam Key Concepts Eliminate the ManagedBean – bind directly to our entity and action classes Enhanced context model Conversation Business process Depend less on xml (faces-config) Use annotations instead Bijection  – for stateful components  Dynamic, contextual, bidirectional Constraints specified on the model, not in the view
AGENDA The Java EE 5 Programming Model Introduction to Seam Refactor to use the Seam Framework Seam Portability Q&A
Seam Registration Application  JSF Context DB Action Class Entity Class Seam Framework JSF Components RegisterActionBean User
Integrating the Seam Framework Additions... EJB Module (jar) Include jboss-seam.jar seam.properties Web Module (war) faces-config.xml SeamPhaseListener web.xml jndiPattern SeamListener
DEMO
faces-config.xml <managed-bean-name> user </... <managed-bean-class>org.ex... 4. ManagedBean userName name password register @Name(&quot; register &quot;) RegisterActionBean user em register 2. User @Name(&quot; use r &quot;)  @Scope(ScopeType.EVENT) username name password getters & setters 1. <h:inputText id=&quot;userName&quot; value=&quot;#{ user . username }&quot; ... <h:commandButton ... action=&quot;#{ register . register }&quot;/>  ... GONE!!! register.jsp 3.
DEMO
User.java (1 of 2) @Entity @Name(&quot;user&quot;)   @Scope(ScopeType.Event)   @Table(name=&quot;users&quot;)   public class User implements Serializable{ private String  username;  private String password; private String name; public User(String name, String password,  String username){ this.name = name; this.password = password; this.username = username; }...
User.java  (2 of 2) public User() {}  @Length(min=5, max=15)   public String getPassword(){ return password; }  public String getName(){ return name; } @Length(min=5, max=15)   public String getUsername(){ return username; }
RegisterAction.java  @Stateless  @Name(&quot;register&quot;)   public class RegisterAction implements Register{ @In  private User user;   @PersistenceContext  private EntityManager em; public String register(){  List existing = em.createQuery(&quot;select username  from User where username=:username&quot;) .setParameter(&quot;username&quot;, user.getUsername() ) .getResultList(); if (existing.size()==0){ em.persist(user); return  &quot;success&quot; ;  }else{  FacesMessages.instance().add(&quot;User  #{user.username}  already exists&quot;); return null; }}}
AGENDA The Java EE 5 Programming Model Introduction to Seam Refactor to use the Seam Framework Seam Portability Q&A
Seam on GlassFish Add missing JBoss Libraries: hibernate-all.jar thirdparty-all.jar Change Persistence Unit to TopLink Update web.xml JndiPattern: java:comp/env/ RegisterAction EJB reference
DEMO
Summary Hopefully you've learned how to start using the Seam framework in your existing JSF / EJB 3.0 applications. There's much more to Seam, I've just touched the surface.
Repeat these demos yourself by visiting my blog at  http://weblogs.java.net/blog/bleonard
Questions & Answers
Ad

More Related Content

What's hot (19)

Introduction to Polymer and Firebase - Simon Gauvin
Introduction to Polymer and Firebase - Simon GauvinIntroduction to Polymer and Firebase - Simon Gauvin
Introduction to Polymer and Firebase - Simon Gauvin
Simon Gauvin
 
Implicit objects advance Java
Implicit objects advance JavaImplicit objects advance Java
Implicit objects advance Java
Darshit Metaliya
 
Jstl 8
Jstl 8Jstl 8
Jstl 8
kashyapkhatri123
 
Java Web Programming [8/9] : JSF and AJAX
Java Web Programming [8/9] : JSF and AJAXJava Web Programming [8/9] : JSF and AJAX
Java Web Programming [8/9] : JSF and AJAX
IMC Institute
 
Implicit object.pptx
Implicit object.pptxImplicit object.pptx
Implicit object.pptx
chakrapani tripathi
 
Jsp Introduction Tutorial
Jsp Introduction TutorialJsp Introduction Tutorial
Jsp Introduction Tutorial
APSMIND TECHNOLOGY PVT LTD.
 
Data Access with JDBC
Data Access with JDBCData Access with JDBC
Data Access with JDBC
BG Java EE Course
 
Trustparency web doc spring 2.5 & hibernate
Trustparency web doc   spring 2.5 & hibernateTrustparency web doc   spring 2.5 & hibernate
Trustparency web doc spring 2.5 & hibernate
trustparency
 
Design patterns in Magento
Design patterns in MagentoDesign patterns in Magento
Design patterns in Magento
Divante
 
Java beans
Java beansJava beans
Java beans
Sher Singh Bardhan
 
Design patterns in PHP
Design patterns in PHPDesign patterns in PHP
Design patterns in PHP
Jason Straughan
 
JSP Error handling
JSP Error handlingJSP Error handling
JSP Error handling
kamal kotecha
 
JavaScript
JavaScriptJavaScript
JavaScript
Sunil OS
 
Java Web Programming [5/9] : EL, JSTL and Custom Tags
Java Web Programming [5/9] : EL, JSTL and Custom TagsJava Web Programming [5/9] : EL, JSTL and Custom Tags
Java Web Programming [5/9] : EL, JSTL and Custom Tags
IMC Institute
 
Jsp lecture
Jsp lectureJsp lecture
Jsp lecture
Tata Consultancy Services
 
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
탑크리에듀(구로디지털단지역3번출구 2분거리)
 
Jsp/Servlet
Jsp/ServletJsp/Servlet
Jsp/Servlet
Sunil OS
 
Jsp
JspJsp
Jsp
Pooja Verma
 
hibernate with JPA
hibernate with JPAhibernate with JPA
hibernate with JPA
Mohammad Faizan
 
Introduction to Polymer and Firebase - Simon Gauvin
Introduction to Polymer and Firebase - Simon GauvinIntroduction to Polymer and Firebase - Simon Gauvin
Introduction to Polymer and Firebase - Simon Gauvin
Simon Gauvin
 
Implicit objects advance Java
Implicit objects advance JavaImplicit objects advance Java
Implicit objects advance Java
Darshit Metaliya
 
Java Web Programming [8/9] : JSF and AJAX
Java Web Programming [8/9] : JSF and AJAXJava Web Programming [8/9] : JSF and AJAX
Java Web Programming [8/9] : JSF and AJAX
IMC Institute
 
Trustparency web doc spring 2.5 & hibernate
Trustparency web doc   spring 2.5 & hibernateTrustparency web doc   spring 2.5 & hibernate
Trustparency web doc spring 2.5 & hibernate
trustparency
 
Design patterns in Magento
Design patterns in MagentoDesign patterns in Magento
Design patterns in Magento
Divante
 
JavaScript
JavaScriptJavaScript
JavaScript
Sunil OS
 
Java Web Programming [5/9] : EL, JSTL and Custom Tags
Java Web Programming [5/9] : EL, JSTL and Custom TagsJava Web Programming [5/9] : EL, JSTL and Custom Tags
Java Web Programming [5/9] : EL, JSTL and Custom Tags
IMC Institute
 
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
탑크리에듀(구로디지털단지역3번출구 2분거리)
 
Jsp/Servlet
Jsp/ServletJsp/Servlet
Jsp/Servlet
Sunil OS
 

Viewers also liked (8)

Os Pittaro
Os PittaroOs Pittaro
Os Pittaro
oscon2007
 
Os Schlossnagle Theo
Os Schlossnagle TheoOs Schlossnagle Theo
Os Schlossnagle Theo
oscon2007
 
Os Fetterupdated
Os FetterupdatedOs Fetterupdated
Os Fetterupdated
oscon2007
 
Os Nolen Gebhart
Os Nolen GebhartOs Nolen Gebhart
Os Nolen Gebhart
oscon2007
 
Os Lonergan
Os LonerganOs Lonergan
Os Lonergan
oscon2007
 
Os Nightingale
Os NightingaleOs Nightingale
Os Nightingale
oscon2007
 
Os Vandeven
Os VandevenOs Vandeven
Os Vandeven
oscon2007
 
J Ruby Whirlwind Tour
J Ruby Whirlwind TourJ Ruby Whirlwind Tour
J Ruby Whirlwind Tour
oscon2007
 
Os Schlossnagle Theo
Os Schlossnagle TheoOs Schlossnagle Theo
Os Schlossnagle Theo
oscon2007
 
Os Fetterupdated
Os FetterupdatedOs Fetterupdated
Os Fetterupdated
oscon2007
 
Os Nolen Gebhart
Os Nolen GebhartOs Nolen Gebhart
Os Nolen Gebhart
oscon2007
 
Os Nightingale
Os NightingaleOs Nightingale
Os Nightingale
oscon2007
 
J Ruby Whirlwind Tour
J Ruby Whirlwind TourJ Ruby Whirlwind Tour
J Ruby Whirlwind Tour
oscon2007
 
Ad

Similar to Os Leonard (20)

JavaEE Spring Seam
JavaEE Spring SeamJavaEE Spring Seam
JavaEE Spring Seam
Carol McDonald
 
Seam Introduction
Seam IntroductionSeam Introduction
Seam Introduction
ihamo
 
Jsp
JspJsp
Jsp
DSKUMAR G
 
Struts2
Struts2Struts2
Struts2
yuvalb
 
Custom Action Framework
Custom Action FrameworkCustom Action Framework
Custom Action Framework
Alfresco Software
 
Spring Capitulo 05
Spring Capitulo 05Spring Capitulo 05
Spring Capitulo 05
Diego Pacheco
 
Struts Overview
Struts OverviewStruts Overview
Struts Overview
elliando dias
 
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
Carles Farré
 
Struts 2 + Spring
Struts 2 + SpringStruts 2 + Spring
Struts 2 + Spring
Bryan Hsueh
 
jBPM5 in action - a quickstart for developers
jBPM5 in action - a quickstart for developersjBPM5 in action - a quickstart for developers
jBPM5 in action - a quickstart for developers
Kris Verlaenen
 
ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group PresentationActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentation
ipolevoy
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2
wiradikusuma
 
Struts2
Struts2Struts2
Struts2
Scott Stanlick
 
Strutsjspservlet
Strutsjspservlet Strutsjspservlet
Strutsjspservlet
Sagar Nakul
 
Strutsjspservlet
Strutsjspservlet Strutsjspservlet
Strutsjspservlet
Sagar Nakul
 
Struts,Jsp,Servlet
Struts,Jsp,ServletStruts,Jsp,Servlet
Struts,Jsp,Servlet
dasguptahirak
 
A Complete Tour of JSF 2
A Complete Tour of JSF 2A Complete Tour of JSF 2
A Complete Tour of JSF 2
Jim Driscoll
 
Jsfsunum
JsfsunumJsfsunum
Jsfsunum
cagataycivici
 
java ee 6 Petcatalog
java ee 6 Petcatalogjava ee 6 Petcatalog
java ee 6 Petcatalog
Carol McDonald
 
Facelets
FaceletsFacelets
Facelets
lingli1031
 
Seam Introduction
Seam IntroductionSeam Introduction
Seam Introduction
ihamo
 
Struts2
Struts2Struts2
Struts2
yuvalb
 
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
Carles Farré
 
Struts 2 + Spring
Struts 2 + SpringStruts 2 + Spring
Struts 2 + Spring
Bryan Hsueh
 
jBPM5 in action - a quickstart for developers
jBPM5 in action - a quickstart for developersjBPM5 in action - a quickstart for developers
jBPM5 in action - a quickstart for developers
Kris Verlaenen
 
ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group PresentationActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentation
ipolevoy
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2
wiradikusuma
 
Strutsjspservlet
Strutsjspservlet Strutsjspservlet
Strutsjspservlet
Sagar Nakul
 
Strutsjspservlet
Strutsjspservlet Strutsjspservlet
Strutsjspservlet
Sagar Nakul
 
A Complete Tour of JSF 2
A Complete Tour of JSF 2A Complete Tour of JSF 2
A Complete Tour of JSF 2
Jim Driscoll
 
Ad

More from oscon2007 (20)

Solr Presentation5
Solr Presentation5Solr Presentation5
Solr Presentation5
oscon2007
 
Os Borger
Os BorgerOs Borger
Os Borger
oscon2007
 
Os Harkins
Os HarkinsOs Harkins
Os Harkins
oscon2007
 
Os Fitzpatrick Sussman Wiifm
Os Fitzpatrick Sussman WiifmOs Fitzpatrick Sussman Wiifm
Os Fitzpatrick Sussman Wiifm
oscon2007
 
Os Bunce
Os BunceOs Bunce
Os Bunce
oscon2007
 
Yuicss R7
Yuicss R7Yuicss R7
Yuicss R7
oscon2007
 
Performance Whack A Mole
Performance Whack A MolePerformance Whack A Mole
Performance Whack A Mole
oscon2007
 
Os Fogel
Os FogelOs Fogel
Os Fogel
oscon2007
 
Os Lanphier Brashears
Os Lanphier BrashearsOs Lanphier Brashears
Os Lanphier Brashears
oscon2007
 
Os Tucker
Os TuckerOs Tucker
Os Tucker
oscon2007
 
Os Fitzpatrick Sussman Swp
Os Fitzpatrick Sussman SwpOs Fitzpatrick Sussman Swp
Os Fitzpatrick Sussman Swp
oscon2007
 
Os Furlong
Os FurlongOs Furlong
Os Furlong
oscon2007
 
Os Berlin Dispelling Myths
Os Berlin Dispelling MythsOs Berlin Dispelling Myths
Os Berlin Dispelling Myths
oscon2007
 
Os Kimsal
Os KimsalOs Kimsal
Os Kimsal
oscon2007
 
Os Pruett
Os PruettOs Pruett
Os Pruett
oscon2007
 
Os Alrubaie
Os AlrubaieOs Alrubaie
Os Alrubaie
oscon2007
 
Os Keysholistic
Os KeysholisticOs Keysholistic
Os Keysholistic
oscon2007
 
Os Jonphillips
Os JonphillipsOs Jonphillips
Os Jonphillips
oscon2007
 
Os Urnerupdated
Os UrnerupdatedOs Urnerupdated
Os Urnerupdated
oscon2007
 
Adventures In Copyright Reform
Adventures In Copyright ReformAdventures In Copyright Reform
Adventures In Copyright Reform
oscon2007
 
Solr Presentation5
Solr Presentation5Solr Presentation5
Solr Presentation5
oscon2007
 
Os Fitzpatrick Sussman Wiifm
Os Fitzpatrick Sussman WiifmOs Fitzpatrick Sussman Wiifm
Os Fitzpatrick Sussman Wiifm
oscon2007
 
Performance Whack A Mole
Performance Whack A MolePerformance Whack A Mole
Performance Whack A Mole
oscon2007
 
Os Lanphier Brashears
Os Lanphier BrashearsOs Lanphier Brashears
Os Lanphier Brashears
oscon2007
 
Os Fitzpatrick Sussman Swp
Os Fitzpatrick Sussman SwpOs Fitzpatrick Sussman Swp
Os Fitzpatrick Sussman Swp
oscon2007
 
Os Berlin Dispelling Myths
Os Berlin Dispelling MythsOs Berlin Dispelling Myths
Os Berlin Dispelling Myths
oscon2007
 
Os Keysholistic
Os KeysholisticOs Keysholistic
Os Keysholistic
oscon2007
 
Os Jonphillips
Os JonphillipsOs Jonphillips
Os Jonphillips
oscon2007
 
Os Urnerupdated
Os UrnerupdatedOs Urnerupdated
Os Urnerupdated
oscon2007
 
Adventures In Copyright Reform
Adventures In Copyright ReformAdventures In Copyright Reform
Adventures In Copyright Reform
oscon2007
 

Recently uploaded (20)

TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 

Os Leonard

  • 1. Refactoring to Seam Brian Leonard Technology Evangelist Sun Microsystems, Inc.
  • 2. AGENDA The Java EE 5 Programming Model Introduction to Seam Refactor to use the Seam Framework Seam Portability Q&A
  • 3. Java EE 5 Programming Model Registration Application Managed Bean Entity Class
  • 5. Java EE 5 Programming Model JSF Context DB Registration Application Managed Bean JSF Components Action Class Entity Class RegisterActionBean User ManagedBean
  • 6. register.jsp: JSF In Action <td> Username </td> <td> < h:inputText id = &quot;userName&quot; value = &quot; #{ user.username } &quot; required = &quot;true&quot; > < f:validateLength minimum = &quot;5&quot; maximum = &quot;15 &quot; / > <td> Real Name </td> <td> < h:inputText id = &quot;name&quot; value = &quot; #{ user.name } &quot; required = &quot;true&quot; > <td> Password </td> <td> < h:inputSecret id = &quot;password&quot; value = &quot; #{ user.password } &quot; required = &quot;true&quot; > < f:validateLength minimum = &quot;5&quot; maximum = &quot;15 &quot; / > < h:commandButton id = &quot;registerCommand&quot; type = &quot;submit&quot; value = &quot;Register&quot; action = &quot; #{ user.register } &quot; / > A JSF Validator
  • 7. register.jsp & BackingBean ... <td> Username </td> <td> < h:inputText id = &quot;userName&quot; value = &quot; #{ user.username} &quot; ... <td> Real Name </td> <td> < h:inputText id = &quot;name&quot; value = &quot; #{ user.name} &quot; ... <td> Password </td> <td> < h:inputSecret id = &quot;password&quot; value = &quot; #{ user.password} &quot; ... < h:commandButton id = &quot;registerCommand&quot; type = &quot;submit&quot; value = &quot;Register&quot; action = &quot; #{ user.register} &quot; / > ... ManagedBean username name password register “ user”
  • 8. Managed Beans Configuration ... <managed-bean> < managed-bean-name > user </managed-bean-name> < managed-bean-class > org.examples.jsf. ManagedBean </managed-bean-class> <managed-bean-scope> request </managed-bean-scope> </managed-bean> ... faces-config.xml <td> < h:inputText id = &quot;userName&quot; value = &quot; #{ user.username} &quot;
  • 9. Managed Bean public class ManagedBean { private String username ; private String name ; private String password ; public String getUsername() { return username; } Public String setUsernaame(String username) { this.username=username; } ... private RegisterActionLocal registerActionBean; private InitialContext ctx; { try { ctx = new InitialContext(); registerActionBean = (RegisterActionLocal) ctx.lookup(&quot;registration/RegisterActionBean/local&quot;); } catch (NamingException ex) { ex.printStackTrace(); } } public String register () { return registerActionBean.register(username, name, password); }
  • 10. EJB 3.0 Dramatic simplification of all bean types Regular Java classes (POJO) @ Stateless, @ Stateful, @ MessageDriven Use standard interface inheritance Dependency injection Instead of JNDI Interceptors Entity Beans (CMP) replaced with JPA
  • 11. Java Persistence API (JPA) Single persistence API for Java EE AND Java SE Much simpler the EJB CMP At least three implementations (all open source): Hibernate (JBoss) TopLink Essentials (Oracle) Kodo/Open JPA (BEA) Configured via persistence.xml
  • 12. JPA – Object Relational Mapping Developer works with objects Database queries return objects Object changes persist to the database Data transformation is handled by the persistence provider (Hibernate, Toplink, etc.) Annotations define how to map objects to tables @ Entity marks a regular java class as an entity Class atributes map to table columns Can be customized with @ Column Manage relationships: @ OneToMany
  • 13. Our Entity Bean @Entity @Table(name=&quot;users&quot;) public class User implements Serializable{ @Id private String username; private String password; private String name; public User(String name, String password, String username){ this.name = name; this.password = password; this.username = username; } //getters and setters...
  • 14. JPA Entity Manager Entity Manger stores/retrieves data Inject Entity Manager: @PersistenceContext private EntityManager em; Create an instance of the entity: User u = new User(params); Use Entity Manager methods to persist data: em.persist(u); em.merge(u); em.delete(u); Query using EJB QL or SQL User u = em.find(User.class, param);
  • 15. Our Action Bean @Stateless public class RegisterAction implements Register{ @PersistenceContext private EntityManager em; public String register(String username, String name, String password){ List existing = em.createQuery (&quot;select username from User where username=:username&quot;) .setParameter(&quot;username&quot;, username ) .getResultList(); if (existing.size()==0){ // Create a new user User user = new User(username, name, password) em.persist(user) ; return &quot;success&quot; ; } else { FacesContext facesContext = FacesContext.getCurrentInstance(); FacesMessage message = new FacesMessage(username + &quot; already exists&quot;); facesContext.addMessage(null, message); return null; }}}
  • 16. AGENDA The Java EE 5 Programming Model Introduction to Seam Refactor to use the Seam Framework Seam Portability Q&A
  • 17. JBoss Seam Application Framework for integrating JSF and EJB 3 component models: Bridge web-tier and EJB tier session contexts Enable EJB 3.0 components to be used as JSF managed beans Integrated AjAX solutions from ICEfaces and Ajax4JSF Improved state management Prototype for JSR 299: Web Beans
  • 18. JBoss Seam Key Concepts Eliminate the ManagedBean – bind directly to our entity and action classes Enhanced context model Conversation Business process Depend less on xml (faces-config) Use annotations instead Bijection – for stateful components Dynamic, contextual, bidirectional Constraints specified on the model, not in the view
  • 19. AGENDA The Java EE 5 Programming Model Introduction to Seam Refactor to use the Seam Framework Seam Portability Q&A
  • 20. Seam Registration Application JSF Context DB Action Class Entity Class Seam Framework JSF Components RegisterActionBean User
  • 21. Integrating the Seam Framework Additions... EJB Module (jar) Include jboss-seam.jar seam.properties Web Module (war) faces-config.xml SeamPhaseListener web.xml jndiPattern SeamListener
  • 22. DEMO
  • 23. faces-config.xml <managed-bean-name> user </... <managed-bean-class>org.ex... 4. ManagedBean userName name password register @Name(&quot; register &quot;) RegisterActionBean user em register 2. User @Name(&quot; use r &quot;) @Scope(ScopeType.EVENT) username name password getters & setters 1. <h:inputText id=&quot;userName&quot; value=&quot;#{ user . username }&quot; ... <h:commandButton ... action=&quot;#{ register . register }&quot;/> ... GONE!!! register.jsp 3.
  • 24. DEMO
  • 25. User.java (1 of 2) @Entity @Name(&quot;user&quot;) @Scope(ScopeType.Event) @Table(name=&quot;users&quot;) public class User implements Serializable{ private String username; private String password; private String name; public User(String name, String password, String username){ this.name = name; this.password = password; this.username = username; }...
  • 26. User.java (2 of 2) public User() {} @Length(min=5, max=15) public String getPassword(){ return password; } public String getName(){ return name; } @Length(min=5, max=15) public String getUsername(){ return username; }
  • 27. RegisterAction.java @Stateless @Name(&quot;register&quot;) public class RegisterAction implements Register{ @In private User user; @PersistenceContext private EntityManager em; public String register(){ List existing = em.createQuery(&quot;select username from User where username=:username&quot;) .setParameter(&quot;username&quot;, user.getUsername() ) .getResultList(); if (existing.size()==0){ em.persist(user); return &quot;success&quot; ; }else{ FacesMessages.instance().add(&quot;User #{user.username} already exists&quot;); return null; }}}
  • 28. AGENDA The Java EE 5 Programming Model Introduction to Seam Refactor to use the Seam Framework Seam Portability Q&A
  • 29. Seam on GlassFish Add missing JBoss Libraries: hibernate-all.jar thirdparty-all.jar Change Persistence Unit to TopLink Update web.xml JndiPattern: java:comp/env/ RegisterAction EJB reference
  • 30. DEMO
  • 31. Summary Hopefully you've learned how to start using the Seam framework in your existing JSF / EJB 3.0 applications. There's much more to Seam, I've just touched the surface.
  • 32. Repeat these demos yourself by visiting my blog at http://weblogs.java.net/blog/bleonard