Presentation is loading. Please wait.

Presentation is loading. Please wait.

JBoss Seam Introduction Xiaogang Cao, RedSaga

Similar presentations


Presentation on theme: "JBoss Seam Introduction Xiaogang Cao, RedSaga"— Presentation 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  jBPM transition events  Seam page actions  Seam component-driven events   @Name("helloWorld") public class HelloWorld { @RaiseEvent("hello") public void sayHello() { FacesMessages.instance().add("Hello World!"); } } 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 YuanMichael Juntao Yuan

14 Seam Component (cont.2)  @Entity @Name("greeter") 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; } }  Please enter your name:

15 Seam Component (cont.3)  @Stateless @Interceptors(SeamInterceptor.class) @Name("manager") public class ManagerAction implements Manager { @In private Greeter greeter; @Out private List allGreeters; @PersistenceContext private EntityManager em; public String sayHello () { em.persist (greeter); allGreeters = em.createQuery("from Greeter g").getResultList(); return null; } }  The following persons have said "hello" to JBoss Seam:  ---------------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  Remote.js  Make the AJAX call Seam.Component.getInstance("helloAction").sayHello(name, sayHelloCallback);  Return fields is been controlled at server side @WebRemote(exclude = {"widgetList.secret", "widgetMap[value].secret"}) 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 http://wiki.redsaga.com/confluence/display/SeamRef/Seam+1.2. 1+GA+Reference+Translate+Overview Coming soon!  http://www.ucosoft.com http://www.ucosoft.com


Download ppt "JBoss Seam Introduction Xiaogang Cao, RedSaga"

Similar presentations


Ads by Google