Intro to Seam Joseph Faisal Nusairat www.petradesigns.com February 15, 2008 Who Am I?
Joseph Faisal Nusairat Author Beginning JBoss Seam Practical Grails Speaker JUGs Codemash CRB Hobbies Bodybuilding Rock Climbing Broadway Musicals
I LOVE TECHNOLOGIES
Where were we?
History of Java Web Development Started off with Servlets / JSP Manually created dozens of servlets, even with JDBC information Hard coded JSPs
We Evolved
We Evolved
We Created Patterns We Created Simplicity by Making Complexity
Patterns for everything Patterns for the front Patterns for the middle Patterns for the back
Dark Times that We Thought Were Good
Change Was In The Air
10 Minutes that Changed Web Development
What about Java?
Why didn’t we have this in Java? Was Java inferior? WHH?
Change Was In The Air
Faster Cleaner Smaller Much Smaller
How Was Rails Special
Convention over Configuration Don’t Repeat Yourself What Was Java’s Answer
Lighter Faster More Aggressive Frameworks
We Need Frameworks that are easier and gives us functionality we want and need, not stuff we don’t need.
Spring 1.0
Spring 2.0
Seam 2.0
• The Next Level
What is Seam?
• An integration framework True next generation integration framework
- http://labs.jboss.com/jbossseam
Basics (Liberation Sans Bold, 28 pt)
Integration of Layers Links JSF + EJB3 Much much much more Can be deployed in Tomcat container with Java Beans and Hibernate More later? GORM maybe?
What New in JSF & EJB3?
EJB 3 Ability to execute without an application server, so good unit tests can be created. The code-compile-package-deploy cycle was shortened, Lack of direction with EJB 2.0 JSF Created to handle deficiencies in the Servlet Specification. POJO based backing beans. Component based pages.
What Did Seam do With EJB3 + JSF
Backing JSF Page EJB3 XBean Remember
All you need though is backing beans and Hibernate. Seam will provide the of the functionality and more. You can even use Groovy objects.
Hello World
Standard Hello World Use JSF + EJB3
Hello World - JSF
Hello World - EJB3
@Name(“helloWorld”) public class HelloWorldAction implements HelloWorld {
private String outputText;
@Create public void init() { outputText = “Hello World”; } }
Garage Sale Application
A simple garage sale application We will use full JSF - SB - EB
JSF Add your Garage Sale
City:
@Name("sellerManager") @ S tateless public class SellerManagerAction implements SellerManager { @PersistenceContext EntityManager em;
Hous@Ine house;
@Logger Log log; public String createGarageSale() {
em.pe log.info("rsist(houAdd se);house - #{house}"); return "/saleItemAdd.jsp"; } } JSF
@Name("house") @E n tity public class House {
@Id @GeneratedValue private long houseId;
@NotNull(message="Address is required") @Length(min=5, max=100, message="Address should be between 5 and 100") private String address;
@NotNull(message="City is required") @L e ngth(min=1, max=100, message="City should be between 1 and 100") private String city; }
IoC - Inversion of Control aka Dependency Injection aka Bijection in the case of Seam Part of Seam’s Core Power
Seam Contexts
Stateless Context Session Context Application Context Event Context Page Context Conversation Context Business Process Context
The Big 4 Contexts
Stateless For items that do not require state Session To be used for sesion information Application Used where only one instance is required Event Alive from the restore view to the render response view
Page Context
Context that is used when call is originating from the same page Useful for list and callbacks to the page Data is serialized to the client
Conversation Context
Allows for spanning of multiple calls Holds state for spanning of multiple calls in the same window The conversations can be started, stopped, and joined via the Seam component or the page itself
Conversation Example @Stateful @Name("bookingCart") @Conversational() pub li c class BookingCartBean implements BookingCart {
@PersistenceContext EntityManager em;
@In(create=true) private Booking booking = null;
@Begin public String starTravelPlans() { return "flights"; }
public String selectHotel() { // ... }
@End public void makeReservation() { em.persist(booking); }
} Business Process Context
Used for jBPM support Allows for storing of the business conversations
Setting of the Contexts
Class level @Name(“test) @Scope(ScopeType.STATELESS) public class TestBean { }
Variable level @In(scope = ScopeType.STATELESS)
Multiple Scopes - @Roles({@Role(name=”tempEvent”, scope=EVENT) @Role(name=”tempPage”, scope=PAGE)}) public class TempBean { }
Roles - Allow the Ability for Multiple Scopes
One Role @Name(“temp”) @Stateless @Scope(SESSION) @Role(name=”tempEvent”, scope=EVENT) public class TempBean {}
Multiple Roles - ... @Roles({@Role(name=”tempEvent”, scope=EVENT) @Role(name=”tempPage”, scope=PAGE)}) public class TempBean { }
Ajax
Biggest buzz word in the industry Asynchronous Javascript and XML Seam supports multiple Ajax implementations Seam Remoting Rich Faces Any JSF Ajax implementation
Seam Remoting
Used to allow JavaScript to interact with Seam components Can use existing instances Create new instances Change display options Gives you batched and unbatched calls to the server
Remoting Hello World Call
OurTestResponse:
< script type="text/javascript" src="seam/remoting/resource/remote.js"/> Seam Component Stateless Session Bean • @Stateless @Name("helloAction") public class HelloWorldAction implements HelloWorld {
publicString sayHello() { return"HelloWorld!"; } } • Interface @Local public interface HelloWorld { @WebRemote String sayHello(); } Batch Calling an Item
• Creating a batch call function sayHello() { Seam.Remoting.startBatch(); Seam.Component.getInstance(...)...... Seam.Component.getInstance(...)... Seam.Remoting.executeBatch(); • Cancel the batch call Seam.Remoting.cancelBatch(); Ability to Use & Instantiate Objets
• Support for all types • Map / Integer / Boolean Enums • Seam Components • New Instance / Get Instance Rich Faces
A partnership of Redhat and Exadel Current version - 3.1.4 Combination of rich GUI functionality and Ajax components that can be used together or seperately. Allows for partial page updates Allows for status images. 47 jBPM
• JBoss Business Process Management • What you must have • Workflow • Actors • Tasks jBPM
• For flow dependent pages • Define how a page moves and the actions for it
Seam Extras
A place that Seam shines Tons and tons and tons of extras.
Email Support • jboss-seam-mail.jar
You can try out Seam by visiting http://labs.jboss.com/jbossseam. Regards, Peter
iText - PDF Generation
• jboss-seam-pdf.jar • PDF or RTF Generation
• Used to switch for switching layouts • This is useful when you want layout type changes • Cascading style sheets • Template changes • Or whatever you want Themes
• Inside the properties file css css/default.css template defaultTemplate.xhtml • Start of your JSF Page
Own custom security framework Roles and permissioning based Permissioning done via drools
Authentication
components.xml
Authenticator @Name(“authenticator”) public class AuthenticationAction {
@In Identity identity
public boolean authenticate() { ... do something ... } }
Identity
Seam default component Fields username password roles (list of string roles) Methods login logout isLoggedIn isSecurityEnabled hasRole(String role) hasPermission(String name, String action, Object ..arg) ... and more ..
Identity
Access @In Identity identity Identity.instance()
Access Control
• Tag Library •
CAPTCHA
Adds ability to have non-computer readable text. Using Add code in web.xml
A form of wiki markup Can allow users that need to have editable forms have rich web display without knowing HTML.
Quartz Dispatcher
Used for asynchronous processing of requests Can be read immediately or scheduled @Asynchronous public QuartzTriggerHandle schedulePayment(@Expiration Date when, @IntervalDuration Long interval, @FinalExpiration Date endDate, Payment payment) { // do the repeating or long running task until endDate } ...... // Schedule the task in the business logic processing code // Starts now, repeats every hour, and ends on May 10th, 2010 Calendar cal = Calendar.getInstance (); cal.set (2010, Calendar.MAY, 10); processor.schedulePayment(new Date(), 60*60*1000, cal.getTime(), payment);
Web Services
RESTful responses always part of Seam As of 2.0 Seam integrates with JBossWS Must be implemented as either a Stateless Session Bean or a POJO
Web Services
@Stateless @WebService(name = "AuctionService", serviceName = "AuctionService") public class AuctionService implements AuctionServiceRemote { @WebMethod public boolean login(String username, String password) { Identity.instance().setUsername(username); Identity.instance().setPassword(password); Identity.instance().login(); return Identity.instance().isLoggedIn(); } }
Seam Extras
Breadcrumbs Charting Spring Integration Hibernate Search
Spring Integration • Sub-headline (Liberation Sans, 25 pt) - Sub-headline (Liberation Sans, 25 pt)
Seam Best Practices • With great power comes great responsibility
Stateful vs Stateless vs JavaBean
Stateful - contains state Used when needing to collect state. Stateless Processing items that require no state at all.
What ARE the Scopes and when to use them
Class level Variable level Multiple Roles Annotation based
Check out the annotations package Write your OWN annotations
Seam Moving Ahead
... where is it going? ...