JSF: Introduction JSF: Introduction, Installation, and Setup
JSF: Introduction JSF: Introduction, Installation, and Setup
JSF: Introduction,
Introduction
Installation, and Setup
Originals of Slides and Source Code for Examples:
http://www.coreservlets.com/JSF-Tutorial/
Overview
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
12
with several levels of indirection.
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
13
14
Disadvantages of JSF (vs. Struts),
Continued
• Support for other display technologies
– JSF iis nott li
limited
it d tto HTML and
d HTTP
HTTP; Struts
St t isi
• Hey! Didn't I say this was an advantage of JSF?
• Confusion vs. file names
– The actual pages used in JSF end in .jsp. But the URLs
used end in .faces or .jsf. This causes many problems; in
particular, in JSF:
• You cannot browse directories and click on links
• It is hard to protect raw JSP pages from access
• It is hard to refer to non-faces pages in faces-
config.xml
fi l
• Self-submit approach
– With Struts,, the form (blah.
( jjspp) and the handler
(blah.do)have different URLs; with JSF they are the
same.
15
Installation
19
• API Javadocs
– http://java.sun.com/j2ee/javaserverfaces/1.1/docs/api/
• Same as the MyFaces version
• Tag library docs
– http://java.sun.com/j2ee/javaserverfaces/1.1/docs/tlddocs/
• Much better than the MyFaces
y version
• MyFaces References
– http://myfaces.apache.org/
• User’s Guide, extensions documentation, FAQs, etc.
• faces-config.xml annotated DTD
– http://horstmann.com/corejsf/faces-config.html
http://horstmann com/corejsf/faces config html
• From Cay Horstmann
21
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.
23 Developed and taught by well-known author and developer. At public venues or onsite at your location.
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
26
Copying jsf-blank-myfaces:
Example (Continued)
• .component file: before
<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="jsf-blank-myfaces">
<wb-resource deploy-path="/" source-path="/WebContent"/>
<wb-resource
b d l
deploy-path="/WEB-INF/classes"
th "/WEB INF/ l " source-path="/src"/>
th "/ "/
<property name="context-root" value="jsf-blank-myfaces"/>
<property name="java-output-path"/>
</wb-module>
</
</project-modules>
j t d l >
Questions?