Your SlideShare is downloading. ×
0
Os Leonard
Os Leonard
Os Leonard
Os Leonard
Os Leonard
Os Leonard
Os Leonard
Os Leonard
Os Leonard
Os Leonard
Os Leonard
Os Leonard
Os Leonard
Os Leonard
Os Leonard
Os Leonard
Os Leonard
Os Leonard
Os Leonard
Os Leonard
Os Leonard
Os Leonard
Os Leonard
Os Leonard
Os Leonard
Os Leonard
Os Leonard
Os Leonard
Os Leonard
Os Leonard
Os Leonard
Os Leonard
Os Leonard
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Os Leonard

780

Published on

Published in: Technology, Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
780
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • Transcript

    • 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
    • 4. DEMO
    • 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
    • 33. Questions & Answers

    ×