[Muir] Seam 2 in practice
-
Upload
javablend -
Category
Technology
-
view
1.946 -
download
3
Transcript of [Muir] Seam 2 in practice
![Page 1: [Muir] Seam 2 in practice](https://reader034.fdocuments.in/reader034/viewer/2022052619/5562d866d8b42a63498b5162/html5/thumbnails/1.jpg)
Seam
Pete MuirJBoss, a Division of Red Hat
http://in.relation.to/Bloggers/Pete
![Page 2: [Muir] Seam 2 in practice](https://reader034.fdocuments.in/reader034/viewer/2022052619/5562d866d8b42a63498b5162/html5/thumbnails/2.jpg)
• 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
Road Map
![Page 3: [Muir] Seam 2 in practice](https://reader034.fdocuments.in/reader034/viewer/2022052619/5562d866d8b42a63498b5162/html5/thumbnails/3.jpg)
!"#$
!"#$"%&%'!(")&*
+&,-.-'&%/&!0&/1%"*"23
4&5!6,7#&8",9
:.&8!0&/1%"*"23
!"#$%
&"%'($%%)*+,$%%
-.,/$
0,/$1"#$
0$,"*'23
4+,"5$(2
62,777
!"#!$%&'"()%*
Application Stack
![Page 4: [Muir] Seam 2 in practice](https://reader034.fdocuments.in/reader034/viewer/2022052619/5562d866d8b42a63498b5162/html5/thumbnails/4.jpg)
JBoss Application Server
WebSphere
Tomcat
Web Logic
Glassfish
JBoss Enterprise Application Platform
JBoss SOA Platform
Where can I run my app?
![Page 5: [Muir] Seam 2 in practice](https://reader034.fdocuments.in/reader034/viewer/2022052619/5562d866d8b42a63498b5162/html5/thumbnails/5.jpg)
• Stateful
• store objects for as long as you need them
• Seam manages all interactions with the context
• dependencies are injected and updated every time a component is accessed
!"#"$%$&&
'($)"
*#+$
,-)($.&#"/-)
!$&&/-)
01&/)$&&!*.-2$&&
344%/2#"/-)
Seam is contextual
![Page 6: [Muir] Seam 2 in practice](https://reader034.fdocuments.in/reader034/viewer/2022052619/5562d866d8b42a63498b5162/html5/thumbnails/6.jpg)
The unified component model@Name("discEditor") @Scope(CONVERSATION) public class DiscEditor {
@In EntityManager entityManager;
@In Session mailSession;
@In @Out Item disc;
@In(scope=SESSION) User user;
// Use the components in some way ;-) }
8
Inject the EntityManager
Inject a JavaMail session
Seam will store the component in the
conversation context
Alias the item from the context, and update the
context if the object changesSpecify the
context to inject from
![Page 7: [Muir] Seam 2 in practice](https://reader034.fdocuments.in/reader034/viewer/2022052619/5562d866d8b42a63498b5162/html5/thumbnails/7.jpg)
• 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
Road Map
![Page 8: [Muir] Seam 2 in practice](https://reader034.fdocuments.in/reader034/viewer/2022052619/5562d866d8b42a63498b5162/html5/thumbnails/8.jpg)
• 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
View a hotel Enter your booking Review and confirm booking
Why do I want an atomic conversation?
![Page 9: [Muir] Seam 2 in practice](https://reader034.fdocuments.in/reader034/viewer/2022052619/5562d866d8b42a63498b5162/html5/thumbnails/9.jpg)
• A conversation scope
• shorter than the session, longer than a request
• demarcated by the application developer
• a conversation per window/tab
ApplicationSession Session
Conversation Conversation
Request Request
What does Seam provide?
![Page 10: [Muir] Seam 2 in practice](https://reader034.fdocuments.in/reader034/viewer/2022052619/5562d866d8b42a63498b5162/html5/thumbnails/10.jpg)
• 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
What does Seam provide?
![Page 11: [Muir] Seam 2 in practice](https://reader034.fdocuments.in/reader034/viewer/2022052619/5562d866d8b42a63498b5162/html5/thumbnails/11.jpg)
• 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}
@Endpublic void saveDisc() { entityManager.flush();}
What does Seam provide?
![Page 12: [Muir] Seam 2 in practice](https://reader034.fdocuments.in/reader034/viewer/2022052619/5562d866d8b42a63498b5162/html5/thumbnails/12.jpg)
• 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)
PERSISTENCE CONTEXT
CONVERSATION
EVENT EVENT
RENDER
RESPONSE
INVOKE
APPLICATION
UPDATE
MODEL
PROCESS
VALIDATIONS
RESTORE
VIEW
APPLY
REQUEST
VALUES
SYSTEM TRANSACTION
FLUSH
How do I manage the system transaction then?
![Page 13: [Muir] Seam 2 in practice](https://reader034.fdocuments.in/reader034/viewer/2022052619/5562d866d8b42a63498b5162/html5/thumbnails/13.jpg)
• 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
Road Map
![Page 14: [Muir] Seam 2 in practice](https://reader034.fdocuments.in/reader034/viewer/2022052619/5562d866d8b42a63498b5162/html5/thumbnails/14.jpg)
• UI orientated controller components
• EntityHome for CRUD
<fwk:entity-home entity-class="com.acme.Disc" name="discHome"/>
<s:decorate template="/edit.xhtml"> <h:inputText value="#{disc.name}" required="true" /></s:decorate><h:commandButton action="#{discHome.update}" value="Save" /><h:commandButton action="#{discHome.remove}" value="Delete" />
Can define in XML or Java for custom
behaviour
Bind directly to the entities, no need for DTOs
Seam provides JSF controls for easy
decoration of fields
Application Framework
![Page 15: [Muir] Seam 2 in practice](https://reader034.fdocuments.in/reader034/viewer/2022052619/5562d866d8b42a63498b5162/html5/thumbnails/15.jpg)
Application Framework• EntityQuery for search
<fwk:entity-query name="discs" ejbql="select d from Disc d" order="d.name" max-results="5"> <fwk:restrictions> <value>lower(d.name) like concat(#{exampleDisc.name}, '%'))</value> </fwk:restrictions></fwk:entity-query>
<component name="exampleDisc" class="com.acme.Artist" scope="session" />
Basic queries can be specified in XML
A prototype, used to bind query parameters
between UI and query
![Page 16: [Muir] Seam 2 in practice](https://reader034.fdocuments.in/reader034/viewer/2022052619/5562d866d8b42a63498b5162/html5/thumbnails/16.jpg)
Application Framework• EntityQuery for search
<h:table value="#{discs.dataModel}" var="d" id="discs"> <h:column> <s:link action="disc" value="#{disc.name}"> <f:param name="discId" value="#{disc.id}" /> </s:link> </h:column></h:table>
<h:form> Filter by name: <h:inputText value="#{exampleDisc.name}"> <a:support reRender="artists" event="onkeyup" /> </h:inputText></h:form>
Search criteria
Output the results
![Page 17: [Muir] Seam 2 in practice](https://reader034.fdocuments.in/reader034/viewer/2022052619/5562d866d8b42a63498b5162/html5/thumbnails/17.jpg)
@Entity public class Item {
@Id @GeneratedValue Long id;
@Length(min=3, max=1000, message="Must be between 3 & 1000 chars") String description;}
• 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
<h:inputText value="#{disc.name}" required="true"> <s:validate /></h:inputText>
Validation
![Page 18: [Muir] Seam 2 in practice](https://reader034.fdocuments.in/reader034/viewer/2022052619/5562d866d8b42a63498b5162/html5/thumbnails/18.jpg)
• 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
Road Map
![Page 19: [Muir] Seam 2 in practice](https://reader034.fdocuments.in/reader034/viewer/2022052619/5562d866d8b42a63498b5162/html5/thumbnails/19.jpg)
• 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
Tooling
![Page 20: [Muir] Seam 2 in practice](https://reader034.fdocuments.in/reader034/viewer/2022052619/5562d866d8b42a63498b5162/html5/thumbnails/20.jpg)
Demo
![Page 21: [Muir] Seam 2 in practice](https://reader034.fdocuments.in/reader034/viewer/2022052619/5562d866d8b42a63498b5162/html5/thumbnails/21.jpg)
• 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
Road Map
![Page 22: [Muir] Seam 2 in practice](https://reader034.fdocuments.in/reader034/viewer/2022052619/5562d866d8b42a63498b5162/html5/thumbnails/22.jpg)
• A community effort
• Uses Granite Data Services or Blaze Data Services
• Check out a couple of demos at
http://www.rationaldeveloper.com
Flex as a view layer
![Page 23: [Muir] Seam 2 in practice](https://reader034.fdocuments.in/reader034/viewer/2022052619/5562d866d8b42a63498b5162/html5/thumbnails/23.jpg)
• 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
JSF 2
![Page 24: [Muir] Seam 2 in practice](https://reader034.fdocuments.in/reader034/viewer/2022052619/5562d866d8b42a63498b5162/html5/thumbnails/24.jpg)
• 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)
What else?
![Page 25: [Muir] Seam 2 in practice](https://reader034.fdocuments.in/reader034/viewer/2022052619/5562d866d8b42a63498b5162/html5/thumbnails/25.jpg)
http://in.relation.to/Bloggers/Pete
http://www.seamframework.org
Q&A