TSSJS2008 Donald Spring For Java Server Faces 1
TSSJS2008 Donald Spring For Java Server Faces 1
Keith Donald
Principal
SpringSource
keith donald at springsource.com
Integration Approaches
• JSF-centric
• Spring-centric
What is Spring?
• The leading Java application framework
Spring delivers
• A container that manages your application architecture
• Helpers for integrating popular ORMs like Hibernate
• Declarative transaction management
• Web services and messaging support
• A platform for developing web applications using the MVC paradigm
Spring and Java EE
What is JavaServerFaces?
• A framework for building user interfaces of Java web applications
JSF delivers
• The leading Java-based web UI component model
Event-driven
Declarative authoring of pages
• Extension points for binding to managed application services
• Extension points for page navigation handling
Spring and JavaServerFaces
JSF-centric (“basic”)
• Looser level of integration
• Spring fits into the JSF world
Behind a javax.faces.FacesServlet
Spring-centric (“deep”)
• Deeper level of integration
• JSF fits into the Spring world
Behind an org.springframework.web.servlet.DispatcherServlet
JSF-centric Integration Approach
Spring 1.x
• Spring manages your application-scoped services
• JSF manages your request-scoped and session-scoped beans
References to services are injected using JSF’s facilities
Spring 2.x
• Spring manages your beans across all scopes
• Can replace managed-bean declarations in faces-config.xml
Benefits of using Spring as a JSF managed
bean provider
Less verbose configuration
• More concise XML syntax
• Elegant annotation-based syntax (Spring 2.5)
Integration Approaches
• JSF-centric
• Spring-centric
Spring is used
• As the managed bean provider
• As the request dispatcher
• As the navigation handler
• As the state manager
• As a lightweight JSF component library
Usage Pattern
Ajax No Yes
View Scope No Yes
Conversation Scope No Yes
Modularization Limited Yes
View Lifecycle Callbacks No Yes
Automatic Redirect After Post No Yes
Protected Views No Yes
Demo Comparsion (3)
Plain JSF Spring-centric JSF
Degradation No Yes
Hot Reloadable Changes No Yes
Exception Handling Limited Yes
URL Control Limited Yes
Bookmarkable Pages Limited Limited
MVC Architecture View Driven Controller Driven
When to use which integration approach?
JSF-centric
• Most common for existing JSF applications
• Most natural for a seasoned JSF developer with little Spring
experience
Spring-centric
• Best for new JSF web applications
Deeper level of integration offers simplicity and power for JSF in
one integrated offering
• Most natural for Spring developers (“Springers”)
Other common JSF pain points addressed
by the Spring-centric approach
Proliferation of verbose XML configuration
• Solved by annotation-based configuration
• Solved by modularizing your web application by domain use case
Poor performance / memory overhead
• Solved by reducing session state and serialization overhead with
ViewScope and ConversationScope