Professional Documents
Culture Documents
JSF: Introduction,
Introduction
Installation, and Setup
Originals of Slides and Source Code for Examples:
http://www.coreservlets.com/JSF-Tutorial/
O
Overview
i
Advantages of JSF
(vs Struts)
(vs.
• Custom components
– JSF makes it relatively easy to combine complex GUIs
into a single manageable component; Struts does not
• Better support for Ajax
– Several third-party component libraries have extensive
Ajax support (Apache Tomahawk, JBoss
Ajax4jsf/RichFaces, Oracle ADF, IceFaces). Struts
doesn't have real component libraries (see above).
• Support for other display technologies
– JSF is not limited to HTML and HTTP; Struts is
• Access to beans by name
– JSF lets you assign names to beans, then you refer to
them by name in the forms. Struts has a complex process
11
with several levels of indirection.
Java EE training: http://courses.coreservlets.com
Advantages of JSF
(vs Struts),
(vs. Struts) Continued
• Expression language
– Th
The JSF expression
i llanguage iis more concise
i and
d
powerful than the Struts bean:write tag.
• This is less advantageous if using JSP 2.0 anyhow.
• Simpler controller and bean definitions
– JSF does not require your controller and bean classes to
extend any particular parent class (e.g., Action) or use
any particular method (e.g., execute). Struts does.
• Simpler config file and overall structure
– Th
The faces-config.xml
f fi l file
fil is
i muchh easier
i tot use than
th isi the
th
struts-config.xml file. In general, JSF is simpler.
• More powerful potential tool support
– The orientation around GUI controls and their handlers
opens possibility of simple to use, drag-and-drop IDEs
12 Java EE training: http://courses.coreservlets.com
I t ll ti
Installation
Development
p
Process by Copying
“Bl k” P
“Blank” Project
j t
Customized Java EE Training: http://courses.coreservlets.com/
Servlets, JSP, Struts, JSF/MyFaces/Facelets, Ajax, GWT, Spring, Hibernate/JPA, Java 5 & 6.
22 Developed and taught by well-known author and developer. At public venues or onsite at your location.
The jjsf-blank-myfaces
y Project
j
• Ready-to-extend Eclipse project
– Contains all required
standard JAR files
– Contains minimal web.xml
web xml
entries
– Contains blank
f
faces-config.xml
fi l file
fil
– Added project facet so that
Eclipse is JSF
JSF-aware
aware
• Especially so special editor is used for faces-config.xml
– Download jsf-blank-myfaces from
htt //
http://www.coreservlets.com/JSF-Tutorial/
l t /JSF T t i l/
• Web site also has extended version of “blank” project that
23
contains MyFaces extensionsJava EE training: http://courses.coreservlets.com
Developing in Eclipse by Copying
“Blank”
Blank Project
• Why copy?
– Creating
C i new JSF apps iin E
Eclipse
li i cumbersome
is b
• R-click project Properties Project Facets
JavaServer Faces has problems if web.xml exists already
• You have to configure JAR file locations
• Issue
– Cutting/pasting
gp g Web apppp in Eclipse
p does not change
g the
context path and internal project deploy name
– Context path can be changed by R-clicking project, then
Properties
p Web Project
j Settings g
– But deployed name is not accessible from within Eclipse!
• Solution
–GGo to fil
file system, edit
di
.settings/org.eclipse.wst.common.component
24 – Change two instances of old project namehttp://courses.coreservlets.com
Java EE training: to new one
Copying jsf-blank-myfaces:
Example
• First, copy project
– R-click on jsf-blank-myfaces, choose “Copy”
– R-click in Project Explorer window, choose “Paste”
• E.g.,
E g name it my
my-jsf-project
jsf project
• Next, edit .component file
– Navigate
g to Eclipse
p workspace/
p projectName/.settin
p j gs
g
Q
Questions?
ti ?