01 JSF Intro PDF
01 JSF Intro PDF
JSF: Introduction,
Installation, and Setup
Originals of Slides and Source Code for Examples:
http://www.coreservlets.com/JSF-Tutorial/
This somewhat old tutorial covers JSF 1, and is left online for those maintaining existing projects. All new projects
should use JSF 2, which is both simpler and more powerful. See http://www.coreservlets.com/JSF-Tutorial/jsf2/.
Overview
Advantages of JSF
(vs. Struts)
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.
Advantages of JSF
(vs. Struts), Continued
Expression language
The JSF expression language is more concise and
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
The faces-config.xml file is much easier to use than is the
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
13
Disadvantages of JSF (vs. Struts),
Continued
Support for other display technologies
JSF is not limited to HTML and HTTP; Struts is
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
Self-submit approach
With Struts, the form (blah.jsp) and the handler
(blah.do)have different URLs; with JSF they are the
same.
14
Installation
18
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 version
MyFaces References
http://myfaces.apache.org/
Users Guide, extensions documentation, FAQs, etc.
faces-config.xml annotated DTD
http://horstmann.com/corejsf/faces-config.html
From Cay Horstmann
20
Development
Process by Copying
Blank Project
Customized Java EE Training: http://courses.coreservlets.com/
Java, JSF 2, PrimeFaces, Servlets, JSP, Ajax, jQuery, Spring, Hibernate, RESTful Web Services, Hadoop, Android.
22 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., name it my-jsf-project
Next, edit .component file
Navigate to Eclipse workspace/projectName/.settings
25
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 deploy-path="/WEB-INF/classes" source-path="/src"/>
<property name="context-root" value="jsf-blank-myfaces"/>
<property name="java-output-path"/>
</wb-module>
</project-modules>
Questions?