[Muir] Seam 2 in practice

2,069 views
2,023 views

Published on

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

No Downloads
Views
Total views
2,069
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
132
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

[Muir] Seam 2 in practice

  1. 1. Seam Pete Muir JBoss, a Division of Red Hat http://in.relation.to/Bloggers/Pete pete.muir@jboss.org
  2. 2. Road Map • What is Seam? • Why should I care about atomic conversations? • How do I quickly build an application with Seam? • What tools are available? • The future
  3. 3. Application Stack "%'($%% :.&8!0&/1%quot;*quot;23 )*+,$%% !quot;#$% !quot;#!$%&'quot;()%* 4&5!6,7#&8quot;,9 -.,/$ !quot;#$ 0,/$1quot;#$ !quot;#$quot;%&%'!(quot;)&* 0$,quot;*'23 4+,quot;5$(2 +&,-.-'&%/&!0&/1%quot;*quot;23 62,777
  4. 4. Where can I run my app? WebSphere Web Logic Tomcat Glassfish JBoss Enterprise JBoss Application Server Application Platform JBoss SOA Platform
  5. 5. !quot;#quot;$%$&& Seam is contextual '($)quot; • Stateful • store objects for as long as you *#+$ need them • Seam manages all interactions ,-)($.&#quot;/-) with the context • dependencies are injected and !$&&/-) updated every time a component is accessed 01&/)$&&!*.-2$&& 344%/2#quot;/-)
  6. 6. Seam will store the The unified component model component in the conversation context @Name(quot;discEditorquot;) @Scope(CONVERSATION) public class DiscEditor { Inject the @In EntityManager entityManager; EntityManager @In Session mailSession; @In @Out Item disc; Inject a JavaMail @In(scope=SESSION) User user; session Alias the item from the // Use the components in some way context, and update the ;-) context if the object } changes Specify the context to inject from 8
  7. 7. Road Map • What is Seam? • Why should I care about atomic conversations? • How do I quickly build an application with Seam? • What tools are available? • The future
  8. 8. Why do I want an atomic conversation? • Here’s a common scenario: • A user has a task to complete which: • spans multiple pages • should be able to click cancel or back at any time, no changes made until the user is finished • should be able to do the same task in multiple windows Review and confirm View a hotel Enter your booking booking
  9. 9. What does Seam provide? • A conversation scope • shorter than the session, longer than a request • demarcated by the application developer • a conversation per window/tab Application Session Session Conversation Conversation Request Request
  10. 10. What does Seam provide? • A conversation scoped persistence context keeps entities attached for the entirety of the user’s task • guarantees object equality • allows lazy loading • An atomic conversation needs to only flush changes at particular points • Only flush the persistence context when explicitly instructed to
  11. 11. What does Seam provide? • An atomic conversation needs to only flush changes at particular points • Need to use a manual flush mode from Hibernate @Begin(flushMode=MANUAL) public void editDisc() { // Load the item to edit } @End public void saveDisc() { entityManager.flush(); }
  12. 12. How do I manage the system transaction then? • Seam manages the system transaction for you • A read-write transaction • A read only transaction for rendering the page (slightly better than Open Session in View) CONVERSATION EVENT EVENT APPLY INVOKE RENDER RESTORE PROCESS UPDATE REQUEST APPLICATION RESPONSE VIEW VALIDATIONS MODEL VALUES PERSISTENCE CONTEXT FLUSH SYSTEM TRANSACTION
  13. 13. Road Map • What is Seam? • Why should I care about atomic conversations? • How do I quickly build an application with Seam? • What tools are available? • The future
  14. 14. Application Framework • UI orientated controller components Can define in XML or Java for custom • EntityHome for CRUD behaviour <fwk:entity-home entity-class=quot;com.acme.Discquot; name=quot;discHomequot;/> <s:decorate template=quot;/edit.xhtmlquot;> <h:inputText value=quot;#{disc.name}quot; required=quot;truequot; /> </s:decorate> <h:commandButton action=quot;#{discHome.update}quot; value=quot;Savequot; /> <h:commandButton action=quot;#{discHome.remove}quot; value=quot;Deletequot; /> Seam provides JSF Bind directly to controls for easy the entities, no decoration of fields need for DTOs
  15. 15. Application Framework • EntityQuery for search <fwk:entity-query name=quot;discsquot; ejbql=quot;select d from Disc dquot; order=quot;d.namequot; max-results=quot;5quot;> <fwk:restrictions> <value>lower(d.name) like concat(#{exampleDisc.name}, '%'))</value> </fwk:restrictions> </fwk:entity-query> Basic queries can be specified in XML <component name=quot;exampleDiscquot; class=quot;com.acme.Artistquot; scope=quot;sessionquot; /> A prototype, used to bind query parameters between UI and query
  16. 16. Application Framework • EntityQuery for search Search criteria <h:form> Filter by name: <h:inputText value=quot;#{exampleDisc.name}quot;> <a:support reRender=quot;artistsquot; event=quot;onkeyupquot; /> </h:inputText> </h:form> Output the results <h:table value=quot;#{discs.dataModel}quot; var=quot;dquot; id=quot;discsquot;> <h:column> <s:link action=quot;discquot; value=quot;#{disc.name}quot;> <f:param name=quot;discIdquot; value=quot;#{disc.id}quot; /> </s:link> </h:column> </h:table>
  17. 17. <h:inputText value=quot;#{disc.name}quot; required=quot;truequot;> <s:validate /> </h:inputText> Validation • Need to report validation errors back to the user on the correct field • BUT normally need to enforce same constraints at the persistence layer and the database @Entity public class Item { @Id @GeneratedValue Long id; @Length(min=3, max=1000, message=quot;Must be between 3 & 1000 charsquot;) String description; }
  18. 18. Road Map • What is Seam? • Why should I care about atomic conversations? • How do I quickly build an application with Seam? • What tools are available? • The future
  19. 19. Tooling • seam-gen - command line tool for generating skeleton project and reverse engineering a database schema using Seam Application Framework • JBoss Developer Studio - Eclipse based IDE • For $99 you get a full installer + JBoss EAP • Based on the freely available JBoss Tools Eclipse plugins
  20. 20. Demo
  21. 21. Road Map • What is Seam? • Why should I care about atomic conversations? • How do I quickly build an application with Seam? • What tools are available? • The future
  22. 22. Flex as a view layer • A community effort • Uses Granite Data Services or Blaze Data Services • Check out a couple of demos at http://www.rationaldeveloper.com
  23. 23. JSF 2 • Easy Component Creation & Templating • Standardizes Facelets • No XML needed to create a component • Built in Ajax support • Many improvements to JSF • lifecycle (performance!) • error handling • navigation
  24. 24. What else? • Seam 2.1 release candidate in the next week or two • Friendly URLs • Identity Management • ACL style permissions • Wicket support • Excel reporting module • Support for JAX-RS (REST)
  25. 25. Q&A http://in.relation.to/Bloggers/Pete http://www.seamframework.org

×