460 likes | 602 Views
JSF 2.2 New Features In Context. Ed Burns Roger Kitain Oracle America, Inc. Program Agenda. Stateless JSF Resource Library Contracts Faces Flows HTML5 Friendly Markup.
E N D
JSF 2.2 New Features In Context Ed BurnsRoger Kitain Oracle America, Inc.
Program Agenda • Stateless JSF • Resource Library Contracts • Faces Flows • HTML5 Friendly Markup
The preceding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract.It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.
Stateless JSF What is state? • Kinds of state in a JSF app • UIComponent state • Model tier state • Persistence tier state
Stateless JSF What is state? • Kinds of state in a JSF app • UIComponent state • Model tier state • Persistence tier state
Stateless JSF What is state? • Kinds of state in a JSF app • UIComponent state • Model tier state • Persistence tier state • Context: Stateless is important mostly as performance concern • See http://bit.ly/LeonardoJsfPerformance Leonardo Uribe’s paper • Much can be done in the way you use JSF to reduce statefulness
Stateless JSF JSF 2.2 approach to stateless • Leverage existing API • Biggest gain for smallest change • Expose existing UIComponent transient property on f:view<f:view transient=“true”> • Spec changes in Restore View Phase, ResponseStateManager • Be advised • Must be on outer-most <f:view> in Facelets inclusion • View scoped managed beans will not work if the view is marked stateless
Stateless JSF Why is this important? • Automatic state management is a key value-add of JSF • Differentiates it from RESTful • Pros • Can be lazy with your UI,
Resource Library Contracts What Is A Resource Library Contract? • Extension of JSF 2.0 Resource Library concept • A “contracts” directory containing: • templates • insertion points in those templates • resources (images, css, JavaScript…) • Any template client that honors this informal contract can be used with any resource library contract that implements that contract
Resource Library Contracts What Is A Resource Library Contract? • Think facelets templates • Builds on JSF 2.0 packaging scheme: • Special directory in web app root (useful for development): • /contracts • Special location in Classpath(useful for deployment): • /META-INF/contracts
Resource Library Contracts Facelets Review
Resource Library Contracts Facelets Review
Resource Library Contracts A Contract is Born
Resource Library Contracts Loading Conventions
Resource Library Contracts Loading Conventions
Resource Library Contracts Loading Conventions
Resource Library Contracts Loading Conventions
Resource Library Contracts Loading Configuration
Resource Library Contracts Loading Configuration
Resource Library Contracts How Do I Use Resource Library Contract? • Convention • Contracts in the application apply to all pages • Contracts discovered at startup; • Assumes no naming collisions • Configuration • Contracts in faces-config.xml: <resource-library-contracts> element • Contracts on <f:view> • contracts attributein<f:view> declares the view is only able touse these named contracts
Faces Flows What Is A Faces Flow? • An application sub-module • Well defined entry and exit • Input and output parameters • Pre and post handlers • Builds on navigation concepts • Inspired, standardized from: • ADF Task Flows • Spring Web Flow • Apache MyFaces CODI
Faces Flows What Is A Faces Flow? • Builds on JSF 2.0 packaging scheme: • Special directory in web app root (useful for development): • /flows • Special location in Classpath (useful for deployment): • /META-INF/flows
Faces Flows What Is A Faces Flow? • Similar to a Java method: • Can be “called” from any place in application • Single entry point • Input parameters and return values • Well defined interface contract • Internal implementation details hidden • New facesFlowScope for flow local storage • New @FlowScopedCDI annotation: automatic activation/passivation
Faces Flows Flow Navigation • Navigation between flow “nodes” • Node types: • View • Method Call • Switch • Flow Call • Flow Return
Faces Flows • Runtime instance: • javax.faces.flow.Flow • JSF 2.2 authoring experience: • XML • Builder (Java Programmatic) • Navigation
Faces Flows View Nodes • Represent pages within the flow • The id attribute is used in navigation rules • Identify the VDL document used to render the view
Faces Flows Method Call Nodes • Invoke logic from flow graph • Decouple invocation of logic from the UI component • Method identified by EL expression • Outcome from either method result or default value
Faces Flows Switch Nodes • Hint: Like a Java switch statement • Make navigation decisions in the flow graph • Generate different outcomes based on boolean EL expression • Default outcome if no expression evaluates to true
Faces Flows Flow Call Nodes • Hint: Like calling a method in Java code • Make calls to other flows • Pass parameter values to called flows • Store values returned from flows
Faces Flows Flow Return Nodes • Hint: Like a Java return statement • Return to calling flow • Identify return values to be passed back to caller
Faces Flows Flow Definition • Name of the flow • Where does the flow start? • Input values • Optional initializer & finalizer
Faces Flows Flow Definition
HTML5 Friendly Markup But First…. A Review • The View Declaration Language (VDL) is used to produce JSF Views Standard Facelets VDL consists of: • HTML Markup • JSF Components (tags in markup) • HTML markup pass through straight to the browser • JSF Components perform server-side actions, during the lifecycle
HTML5 Friendly Markup HTML5 Doctype • HTML5 doctype is always rendered (default) • If you need JSF 2.1 behavior (passing doctype through from source): <faces-config-extension> <facelets-processing> <file-extension>.xhtml</file-extension> <process-as>xhtml</process-as> <facelets-processing> </faces-config-extension>
HTML5 Friendly Markup Pass-through Attributes • Attributes passed to rendered output element directly (components do not process them) • Possible to render HTML5 attributes (or any attribute) not supported by component • Convenient – as HTML5 is still a “work in progress” and could be for sometime
HTML5 Friendly Markup Pass-through Attributes • Example: Namespace Approach • Namespace: xmlns:p=http://xmlns.jcp.org/jsf/passthrough • Markup: <h:inputText id=“input” value=“” p:placeholder=“Enter Text” /> • Rendered output: <input type=“text” id=“input” value=“” placeholder=“Enter Text” />
HTML5 Friendly Markup Pass-through Attributes • Example: Nested Approach • Markup: <h:inputText id=“input” value=“” > <f:passThroughAttribute name=“passthrough” value=“Enter Text”/> </h:inputText> • Rendered output: <input type=“text” id=“input” value=“” placeholder=“Enter Text” /> • You can nest multiple <f:passThroughAttribute> • You can use <f:passThroughAttributes> • You can use EL expressions
HTML5 Friendly Markup Pass-through Elements • “A page without JSF tags” • Links HTML elements to server-side component instances • At least one of the element’s attributes must be in the namespace: http://xmlns.jcp.org/jsf • Type of component created is determined by element name and identifying attribute (if element name alone not sufficient)
HTML5 Friendly Markup Pass-through Elements • Example: • Namespace: xmlns:jsf=“http://xmlns.jcp.org/jsf” • Markup: <head jsf:id=“head=“>…</head> <body jsf:id=“body”> <form jsf:id=“form”> <input type=“text” id=“input” jsf:value=“” placeholder=“Enter Text”/> </form> </body> • All markup elements will be represented as server side JSF components: • <h:head>, <h:body>, <h:form>, <h:inputText>
HTML5 Friendly Markup Pass-through Elements • More mapping examples: • Complete mappings of elements and component tags: • http://docs.oracle.com/javaee/7/api/javax/faces/view/faceletsTagDecorator.html
HTML5 Friendly Markup Pass-through Elements • You can also mix and match markup: <input type=“text” jsf:value=“”> <f:validateLength minimum=“5”/> </input> • What happens if there is no existing mapping? • JSF creates a special component: component-family: javax.faces.Panel renderer-type: javax.faces.passthrough.Element http://docs.oracle.com/javaee/7/javaserverfaces/2.2/vdldocs/facelets/jsf/element.html
Resources • JSF Specification: http://jcp.org/en/jsr/detail?id=344 • JSF Implementation: http://javaserverfaces.java.net/