Seam Introduction


Published on

An effective but simple introduction about JBoss Seam.

Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • h
  • Seam Introduction

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