This session provides an overview of both the JSF and MVC 1.0 frameworks. The frameworks are then compared to each other. Finally, JSF 2.3 upcoming features are previewed.
1. Java EE 8 Web Frameworks
A Look at JavaServer Faces vs MVC
Josh Juneau
2. About Me
• Member of JSF 2.3 (JSR 372) EG
• Member of JSR 378 (Portlet 3.0 Bridge) EG
• Developer/Analyst/DBA @ Fermilab
• Apress Author
• OTN/Java Magazine Contributor
• Member of CJUG
• Java EE Guardians
3. Agenda
• Overview of JavaServer Faces & Demo
• Overview of MVC & Demo
• Feature Comparison
• JSF 2.3 Feature Overview
• Java EE 8 Overall Status
5. JavaServer Faces Overview
JavaServer Faces technology establishes the standard
for building server-side user interfaces for Java EE.
• An API for representing UI components and managing
their state; handling events, server-side validation, and
data conversion; defining page navigation; supporting
internationalization and accessibility; and providing
extensibility for all these features
• JavaServer Faces (JSF) custom tag libraries for
expressing UI components within a view and for wiring
components to server-side objects
6. JavaServer Faces Overview
The well-defined programming model and tag libraries
significantly ease the burden of building and maintaining web
applications with server-side UIs. With minimal effort, you can:
• Drop components onto a page by adding component tags
• Wire component-generated events to server-side application
code
• Bind UI components on a page to server-side data
• Construct a UI with reusable and extensible components
• Save and restore UI state beyond the life of server requests
7. JSF Models
Data tier to work with entity classes (POJOs that
map to database tables) to work with the
underlying database from within a Java EE
application.
• EJBs…no…not J2EE!!!!
• JAX-RS
8. JSF Views
• Tree of Components
• Facelets or HTML
• Expression Language
• Mix with JSTL and other tab libraries, as needed
• Component Libraries
11. JSF Controllers
• Business logic - FacesServlet
• CDI Scopes…No More JSF @ManagedBean
• SessionScoped, ApplicationScoped,
ViewScoped, RequestScoped,
ConversationScoped, FlowScoped,
Dependent, Singleton
• Contextual…State Managed Across Requests
12. JSF Typical Form Submit
Procedure
• User completes form entry by populating form
components.
• User clicks a commandButton, which invokes a
server-side method, and the CDI bean values
are submitted to FacesServlet for processing.
• Action method performs its work and then
returns control to FacesServlet for navigation.
17. JSR 371: MVC 1.0
https://ozark.java.net/
• Action-oriented framework layered on top of JAX-RS
• Manual controller logic…you control your own destiny!
• No UI Components
• You choose your front end technology
18. MVC 1.0
Models
Utilize entity classes for data, or store into CDI bean
Two ways to work with models:
• javax.mvc.Models class
• CDI-Based Models
19. MVC 1.0
Views
ViewEngine Used to Merge Model and View
• Utilize a number of different view technologies
• Ozark Ships with 3 Implementations
• Views reside within WEB-INF/views folder
22. MVC 1.0
Controllers
• Controls the request-processing for an MVC
application.
• JAX-RS Implementation
• Class annotated with @Controller either at class level
or method level.
• Must be CDI Managed
• Possible to create hybrid classes (@Controller at
method level)
23. MVC 1.0
Controllers
• Four return types: String, void, Response, Viewable
• String: returns path to view
• void: requires @javax.mvc.View annotation
• Response: typical javax.ws.rs.core.Response, providing
access to the response
• Viewable: javax.mvc.Viewable containing information ab
the view and how to process
• Default response type text/html, but can be modified with
@Produces
25. MVC 1.0
Views to Controllers - Parameters
Parameters handled via annotations in Controller:
• @PathParam: Used to extract path parameters
• @FormParam: Used to process fields from form
• @QueryParam: Used when parameters appended to
URL
• @BeanParam: Used to inject various request
parameters into a bean
26. MVC 1.0
Views - Redirecting Responses
• JAX-RS
return
Response.seeOther(URI.create(“redirectView”)).build()
• MVC
return “redirect:redirectView”
@RedirectScoped Annotation
• Bean will span at most two requests
• Must be Serializable
27. MVC 1.0
Exception Handling
• Can be applied via try/catch at method level or
globally
return Response.status(BAD_REQUEST).entity("error.jsp").build();
• ExceptionMapper class
28. MVC 1.0
Security
• Utilize ${mvc.csrf.name} and ${mvc.csrf.token} in
form
• javax.mvc.security.CsrfProtection property
• @CsrfValid Annotation at Method Level
30. JSF or MVC?
JSF MVC
• Component Based
• Controller Logic
Automates Processing
• Facelets
• Rapid Development
• Works well with REST
• Stateful…remains across
requests
• Action Based
• Layered on Top of JAX-RS
• Manual Validations/
Conversions
• Many Different View Options
• Fine Control Request/
Response
• Great fit for REST
• No State Across Requests
31. JSR 372: JSF 2.3
Not forgotten with Java EE 8
While scope of update is not very large, new features
and enhancements will help continue making JSF
relevant in today’s world.
Thanks to the OmniFaces folks for adding a number of
features to JSF.
32. JSF 2.3 in Java EE 8
• Two feature drivers: Oracle & Community
• Feature clean-up
• Small new feature set based upon community requests
• Mature standard for building Java EE applications
33. JSF 2.3 - Oracle Focus
Tie up loose ends:
• Specification clarifications
• CDI Alignment
• Others
Small Scale New Features:
• CDI Managed Beans Only
• Ajax Method Invocation
• Multi-component Validation
34. JSF 2.3 - Community Focus
• JSON Ajax Component Rendering
• Stateless enhancements
• GET Enhancements
• Push Support
35. JSF 2.3 New Features
(Implemented)
• Inject ViewMap
@ViewMap
@Inject
Map viewMap;
• Inject UiViewRoot
@Inject
UIViewRoot viewRoot;
• #1332 - Let CDI handle #{view}
• #1331 - Let CDI handle #{application}
• #1254 - contracts attribute too restrictive.
36. JSF 2.3 New Features
(Implemented - ctd)
• #1328 - Let CDI handle #{session} EL resolving
• #1325 - Let CDI handle #{applicationScope}
• #1311 - Let CDI handle #{facesContext} EL resolving
• #1323 - Support @Inject for the applicationMap
@ApplicationMap
@Inject
Map applicationMap;
• #1322 - Simplify #{externalContext} to use
ExternalContextProducer
37. JSF 2.3 New Features
(Implemented - ctd)
• #1309 - Support @Inject for ExternalContext
@Inject ExternalContext externalContext;
• #527 - Support @Inject for FacesContext
@Inject FacesContext facesContext;
• javax.faces.bean.ManagedProperty Replacement
38. JSF 2.3 New Features
(Implemented - ctd)
• #1396 - f:socket for SSE and WebSocket
http://jj-blogger.blogspot.com/2016/02/a-look-at-
upcoming-jsf-23-push-support.html
40. What Is The CJUG?
Chicago Java Users Group is dedicated to the
helping you learn and network.
• Technology community second to none.
• Learn and contribute to Java / JVM ecosystem
• Mentorship and career opportunities
• Have fun and build cool things