API
Tag libraries
Elements of a JSF application:
web pages
set of tags to add components to web page
managed beans
web.xml
optional application configuration resource files to define page navigation rules, configure beans, etc.
a set of custom objects, including custom components, validators, converters, listeners, etc.
optional, custom tags
Execute phrase
Http Request
Restore view
view saved in FacesContext instance
Apply request
component in view tree extracts new value from request parameters and stored locally on each component
any component having "immediate" attribute set to true, then validation / conversion / events handling will be processed here
events broadcast and processed
may call javax.faces.context.FaceContext.renderResponse() to force immediate rendering of response
may call FaceContext.responseComplete() to skip render response phrase (when redirected, submits a request for another JSF, for example)
in the end, components are set to new values
messages / events been queued
Process validations
process all registered validators
complete conversions
if validation / conversion fails, add error message to FacesContext and skip directly to -> render response
events processed
still, may call javax.faces.context.FaceContext.renderResponse() or FaceContext.responseComplete()
Update Model Values
set server-side object properties to components' local values
Process events
Invoke application
Process events
Render phrase
Render response
Http Response
HTML with JSF tags, expression language.
Reference of managed bean - if no name is specified in @Named annotation, it's the class name with first letter in lowercase
Action = response means response.xhtml shall be displayed
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
...
<h:form>
...
<h:inputText id="username"
value="#{hello.name}"
...
<h:commandButton id="submit" value="Submit" action="response"></h:commandButton>
...
Java Bean, annotated
@Named
@RequestScoped
public class Hello {
......
}
javax.inject.Named - identify class as managed bean
javax.enterprise.context.RequestScoped and other scope annotation identify how application data persists and shared
javax.enterprise.context.RequestScoped - single HTTP request
javax.enterprise.context.SessionScoped - user session cross multiple requests
javax.enterprise.context.Application - all user's interactions
javax.faces.flows.FlowScoped - during user interaction with a specific flow of a web application (see Faces Flows)
javax.enterprise.context.Dependent - [study when use]
A content parameter, servlet element and its servlet-mapping element (catching all *.xhtml), and welcome file list need to be specified. Usually it will be automatically generated by tools. See 6.3.1 tutorial.