Seam Introduction

  • 3,798 views
Uploaded on

An effective but simple introduction about JBoss Seam.

An effective but simple introduction about JBoss Seam.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
3,798
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
203
Comments
0
Likes
3

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
  • h

Transcript

  • 1. JBoss Seam Introduction Xiaogang Cao, RedSaga http://www.ucosoft.com 2007-4-19
  • 2. MVC
    • Pros
      • pull the page logic out of mud
      • A clean structure of request process
    • Cons
      • It’s only focus on request/response
      • Modal and View are linked static
      • Very hard to abstract ‘widgets’ in web pages
    • I dreamed : XML,DB,entity, web based data window been unified
  • 3. The Seam way
    • Consider the whole web app in a human understandable way
    • Servlet Context is not enough, people have to write codes to manage state everywhere
    • Seam unified all state management to ‘ Declared State Management’
    • The core cool feature of Seam is ‘Conversation Context’
  • 4. Conversations Samples
    • Create Order:
      • Select a customer
      • Check balance
      • Add a product to detail list
      • Add more products
      • Confirm and assign a Order Number
  • 5. Conversations Samples(cont.)
    • Online Digital Photo Print Wizard
      • Browse for photos, add them to print cart
      • Review and update print qty
      • Print them
    • User profile update wizard
      • View and begin edit of user profile
      • Add a photo
      • Edit details
      • Review changes
      • Confirm change
  • 6. Seam’s Contexts
    • Stateless context
    • Event (or request) context
    • Page context
    • Conversation context
    • Session context / Http Session
    • Business process context / JBPM
    • Application context
    • Contexts.lookupInStatefulContexts()
  • 7. Conversation context
    • Conversation spans more than one page
    • Conversation is a whole interaction of a certain task
    • Conversation may means a ‘User Story’ or a ‘Use Case’
    • Nothing magic
      • it’s implemented by url param(ServerConversationContext) or a client param(ClientConversationContext)
      • Contexts Class use ThreadLocal to store all contexts.
  • 8. Conversation Lifecycle
    • @Begin
    • @End
    • Conversation have timeout
    • Conversation doesn’t result to a transaction
    • Conversations can be nested
    • Conversation can be merged by same id
    • Conversation can be managed by ‘workspace’
  • 9. Business Process Context
    • BusinessProcessContext can span more than 1 user
    • jBPM backend
    • Sample
  • 10. The meaning of 2 additional context
    • Make program much more clear and easy to understand
    • Use conversations and Business Process (jBPM) directly in JSF
    • Eliminate the chance of silly mistakes and memory leaks
    • Reduce the debug time
    • You never want to convert back
  • 11. Events
    • Events
      • JSF events
        • <h:commandButton value=&quot;Click me!&quot; action=&quot;#{helloWorld.sayHello}&quot;/>
      • jBPM transition events
        • <start-page name=&quot;hello&quot; view-id=&quot;/hello.jsp&quot;> <transition to=&quot;hello&quot;> <action expression=&quot;#{helloWorld.sayHello}&quot;/> </transition> </start-page>
      • Seam page actions
        • <pages> <page view-id=&quot;/hello/*&quot; action=&quot;#{helloWorld.sayHello}&quot;/> </pages>
      • Seam component-driven events
        • <components> <event type=&quot;hello&quot;> <action expression=&quot;#{helloListener.sayHelloBack}&quot;/> <action expression=&quot;#{logger.logHello}&quot;/> </event> </components>
        • @Name(&quot;helloWorld&quot;) public class HelloWorld { @RaiseEvent(&quot;hello&quot;) public void sayHello() { FacesMessages.instance().add(&quot;Hello World!&quot;); } }
      • Seam contextual events
        • Lots of build-in events , such as org.jboss.seam.validationFailed
    • No Event object exists in seam. You can pass params if needed
  • 12. Seam Component
    • Seam component is a mix of jsf backingbean(managed bean),service class(normally named as ***Manager or **Service. )
    • It can maintain the states for your objects
    • It can be
      • Stateless session beans
      • Stateful session beans
      • Entity beans
      • JavaBeans
      • Message-driven beans
  • 13. Seam Component (cont.)
    • The key of lightweight container is Dependency Injection (DI).
    • DI uses the lightweight framework container to inject services or other objects into a POJO.
    • The major differences between lightweight frameworks are how they wire container services together and implement Dependency Injection. The service architecture and metadata expression are the key issues here.
    • ‘ Components’ are the ‘Spring beans’ in Seam world
    • Components have the ability to be wired in Web tier
    • ---- Michael Juntao Yuan
  • 14. Seam Component (cont.2)
    • @Entity @Name(&quot;greeter&quot;) public class Greeter implements Serializable {      private long id;      private String name;      @Id(generate=AUTO)      public long getId() { return id;}      public void setId(long id) { this.id = id; }      public String getName() { return name; }      public void setName(String name) { this.name = name; } }
    • <h:form> Please enter your name:<br/> <h:inputText value=&quot;#{greeter.name}&quot; size=&quot;15&quot;/><br/> <h:commandButton type=&quot;submit&quot; value=&quot;Say Hello&quot; action=&quot;#{manager.sayHello}&quot;/> </h:form>
  • 15. Seam Component (cont.3)
    • @Stateless @Interceptors(SeamInterceptor.class) @Name(&quot;manager&quot;) public class ManagerAction implements Manager {    @In    private Greeter greeter;    @Out    private List <Greeter> allGreeters;    @PersistenceContext    private EntityManager em;    public String sayHello () {      em.persist (greeter);      allGreeters = em.createQuery(&quot;from Greeter g&quot;).getResultList();      return null;    } }
    • <p>The following persons have said &quot;hello&quot; to JBoss Seam:</p> <h:dataTable value=&quot;#{ allGreeters }&quot; var=&quot;person&quot;>    <h:column>      <h:outputText value=&quot;#{person.name}&quot;/>    </h:column> </h:dataTable>
    • ---------------above codes from Michael Yuan , http://java.sys-con.com/read/180347.htm
  • 16. Seam bijection
    • In other containers
      • DI happens only when the POJO is created
      • Injection is the action between container and beans
      • the reference does not subsequently change for the lifetime of the component instance
      • This is good for stateless beans
    • For a stateful component, we need to change the reference within different context
    • In Seam
      • injection and outjection are the action between context and components
      • DI happens when the context switches
  • 17. Seam bijection(cont.)
    • Bijection is
      • Contextual
        • Reference can change in difference context
      • bidirectional
        • Values are ‘Injected’ from context, and also ‘Outjected’ to the context
      • dynamic
    • Bijection and contextual components are the soul of Seam!
  • 18. Other cool stuffs
    • JSF with EJB 3.0 (Ajax4jsf,icefaces,..)
    • Enhance to JSF EL
    • Validation
    • Conversation written with JPA considered
    • Build-in Testable
    • Build-in BPM
    • Build-in Security
    • Build-in mail, webmail as a option
  • 19. Develop simplified
    • Rails style seam-gen
    • Template based generation
    • EL support in HQL/EJB-QL
    • simplified annotation based configuration
  • 20. Highly integrated
    • JSF
    • EJB3/JPA
    • JAAS authentication
    • JSP
    • Unified EL
    • JavaMail
    • Portlet
    • buni-meldware mail/web mail
    • Facelets
    • jBPM
    • Hibernate
    • iText
    • Drools
    • JCaptcha
    • Ajax4JSF
    • ICEFaces
    • Spring
    • MyFaces
    • Jboss microcontainer
  • 21. EJB 3.0 or Java Beans?
    • Both EJB 3.0 session beans and entity beans are supported as a component
    • Java Beans also supported
    • EJB 3.0 have declared transactions and state replicate capability
    • Use Java Beans instead of EJB 3.0 allow you use Seam directly in Tomcat, not a EJB 3.0 container
    • Java Beans support hot deploy
  • 22. EJB 3.0 and JavaBeans(Cont.)
    • booking example have several versions
      • /examples/booking is a EJB 3.0 version
      • /examples/hibernate is a Hibernate 3.0 version
      • /examples/icefaces is using icefaces instead of Ajax4JSF
      • /examples/glassfish is a version runs on Java EE 5 reference implementation
    • Tips: Seam has a lot of well written completed examples comparing to hibernate
  • 23. Seam and JSF
    • EJB 3 beans are JSF managed Beans
    • Actually every Component are JSF managed Beans
    • Currently JSF is the only view supported
    • Seam will be a main strength to promote JSF
    • However, JSF is not very popular in China now
  • 24. Seam and iText
    • Pros:
      • Seam use facelets document to generate PDF
    • Cons:
      • Still like a toy, comparing to Crystal Reports or JReport
      • Report is one of very important feature in real world
      • Suggest to use JasperReports as a solid report tool
    • Tips: Foxit Reader ActiveX can render PDF in lighting speed within the IE browser.
  • 25. Seam and AJAX
    • Interface.js
      • <script type=&quot;text/javascript&quot; src=&quot;seam/resource/remoting/interface.js?customerAction&accountAction&quot;></script>
    • Remote.js
      • <script type=&quot;text/javascript&quot; src=&quot;seam/resource/remoting/resource/remote.js&quot;></script>
    • Make the AJAX call
      • Seam.Component.getInstance(&quot;helloAction&quot;).sayHello(name, sayHelloCallback);
    • Return fields is been controlled at server side
      • @WebRemote(exclude = {&quot;widgetList.secret&quot;, &quot;widgetMap[value].secret&quot;})
      • public Widget getWidget();
    • Return Data is typed
      • Primitives / Basic Types ,String, Date,Number, Boolean,Enum, Bag, Map
    • Support subscribe to JMS topic
  • 26. Seam and AJAX(Cont.)
    • Pros:
      • Seam remoting allow seam been used with other client JS library
      • Currently two open source JSF-based AJAX solutions: ICEfaces and Ajax4JSF
    • Cons:
      • Actually, RichFaces also like a toy comparing to dojo or Ext
      • AJAX design pattern is still evolving. Especially in a portal page.
      • Current Seam remote.js is tied too tight with JSF.
      • It’s possible to write a customized Ext dataset to communicate with Seam Remoting, but require many codes.
      • Hope it can support JSON/Burlap in the future and support a dataSet model
  • 27. Seam PageFlow
    • Pros:jPDL visiable XML define
    • Cons: you must use jBPM
  • 28. Seam Security
    • Simple mode and Advanced mode
      • Advanced mode use Drools, provide rule based security checks
    • Authenticate
      • built upon JAAS
      • offers a much more simplified method of authentication
    • Authorization
      • Security API for securing access to components, component methods, and pages
      • Role based security check
    • Security is a major advantage comparing to other frameworks like ROR.
  • 29. Seam and persistence
    • Tight integration with EJB 3.0 entity bean ,JPA and Hibernate
    • No need to say more! 
  • 30. Conclusion
    • Seam is the most advanced J2EE stack now
      • State Management is the most important feature
      • But Seam is also heavy and complex
      • Still lack of advanced Report ability
      • AJAX support is behind era
    • You must use JSF to gain max benefit
      • But JSF is not popular enough
    • Seam can simplify your code
      • Remove glue codes between layers
    • Some of Seam function is not standard yet
      • No, but maybe that isn’t a problem, just like the success of hibernate in EJB 2.0 era.
  • 31. Conclusion(cont.)
    • Ruby improve productivity by using dynamic language and provide a ready to use Rails framework
    • ROR is lack of wide range of libraries support comparing to Java
    • Seam introduce Contextual Components , which will dramatically improve java programmer’s productivity
    • But Seam’s inner complex will cost more time for developers to go in deep
  • 32. Hope
    • resolve the problem of EJB 3 beans hot deploy, that’s really a handy feature
    • Add more views besides JSF. How about Eclipse RAP or Ext?
      • Current client conversation can be used in a full AJAX solution.
    • Exadel can improve the usability of Seam
  • 33. About redsaga
    • www.redsaga.com, an open source community only for matures
    • Open source project hosting service available for good projects
    • Contributed to Hibernate & Spring by organize the translate of reference documents and write book in Chinese
      • Hibernate Core
      • Hibernate Annotations
      • Hibernate EntityManager
      • Spring Reference
    • Seam Reference translation in progress and open for volunteers
      • http://wiki.redsaga.com/confluence/display/SeamRef/Seam+1.2.1+GA+Reference+Translate+Overview
      • Coming soon!
    • http:// www.ucosoft.com