Академический Документы
Профессиональный Документы
Культура Документы
Fahad R. Golra
ECE Paris Ecole d'Ingnieurs - FRANCE
JSF
Servlets
EJB
presentation
layer
application logic
layer
resource management
layer
JPA
Database
3
information system
JSP
Components of JSF
An API for
Why JSF ?
Request Scope
Request Scope
request
client
response
Request Scope
request
response
client 2
7
Request Scope
per request
response
Server
per request
request
Session Scope
request
Server
client
Session Scope
per client
request
Session Scope
per client
response
response
request
response
client 2
8
Application Scope
request
Server
request
client
response
Application Scope
request
response
client 2
9
per application
response
JSF Architecture
10
The UI for the web application manages the objects referenced by the
JSP page.
JSF Lifecycle
Client Browser
client
Restore Value
Re-constitute component
tree
Render Response
12
Apply Request
Values
Process Events,
Validators
Invoke Application
Logic
Update Model
Values
JSF implementation
builds the view of the page
wires event handlers and validators to components in the
view
saves the view in the FacesContext instance
Each component in the tree extracts its new value from the
request parameters by using its decode method
Implementation skips to the render response phase if
renderResponse is called
If events have been queued, the they are broadcasted to
interested listeners
validation, conversion, and events associated with
components having immediate attributes will be processed
during this phase
14
15
16
17
UI Components
UIComponent/UIComponentBase
Base class for all user interface components
Standard UIComponent Subclasses
UICommand, UIForm, UIOutput
UIGraphic, UIInput, UIPanel, UIParameter
UISelectBoolean, UISelectMany, UISelectOne
Example
<h:inputText id=fNameInput"
value="#{UserRegistrationBean.firstName}"/>
19
JSF Validators
20
JSF Converters
21
Navigation
22
24
In Faces-config.xml
<managed-bean>
<managed-bean-name>
LoginFormBean
</managed-bean-name>
<managed-bean-class>
myapp.LoginFormBean
</managed-bean-class>
<managed-bean-scope>
request
</managed-bean-scope>
</managed-bean>
25
26
<f:view>
<f:form formName=logonForm>
<h:panel_grid columns=2>
<h:output_text value=Username:/>
<h:input_text id=username length=16
valueRef=logonBean.username/>
<h:output_text value=Password:/>
<h:input_secret id=password length=16
valueRef=logonBean.password/>
<h:command_button type=submit label=Log On
actionRef=logonBean.logon/>
<h:command_button type=reset label=Reset/>
</h:panel_grid>
</f:form>
</f:view>
27
<navigation-rule>
<from-tree-id> /login.jsp </from-tree-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-tree-id>/menu.jsp</to-tree-id>
</navigation-case>
<navigation-case>
<from-outcome>failed</from-outcome>
<to-tree-id>/error.jsp</to-tree-id>
</navigation-case>
</navigation-rule>
28
<context-param>
<param-name>
javax.faces.application.CONFIG_FILES
</param-name>
<param-value>/WEB-INF/faces-config.xml
</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>
javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup> 1 </load-on-startup>
</servlet>
<!-- Faces Servlet Mapping -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
29
30
JSF
JSP
Components
Rich UI-data-bound
components with events
provided
Custom components
Device
independence
None
Error handling
and validation
Validation framework
Many predefined validators
None
Scripting
Page flow
None
31