JSF

advertisement
Java Server Faces
St. Louis JavaSIG June 8, 2006
Jay Meyer,
Harpoon Technologies
About Me






Master CS from Washington Univ. (wustl.edu)
Software developer for 14 years (1992)
Java Web development since 1999
Certified JBoss Application Developer
Recent projects use Struts, Spring, Hibernate,
JBoss, Oracle
Hibernate consulting thru HarpoonTech, a
JBoss partner
Summary




Brief History of JSF
Motivations for JSF, the Java Landscape
JSF details
Demo apps in MyFaces & Seam
What is Java Server Faces?





JSF is a spec which defines a component-based MVC
framework
JSF 1.2 is included in the larger JEE5 spec
The spec was developed by involving many people
from orgs like Sun, Apache, IBM, Oracle
Not tied to a Web framework, nor a thick-client GUI –
theoretically could be applied to either
Implementations, frameworks:



Sun RI vs. Apache MyFaces
JBoss Seam vs. Apache Struts 2 Shale
IBM, Oracle have proprietary solutions
The Problem with Web apps




HTML? HTML? Java people like Objects, HTML is not Objects
Web programming is more difficult than GUI programming
Java programming is hard – and J2EE is even more difficult:
Servlets? JSP? EJBs!?!
Microsoft has VisualStudio which turns web programming into
drag-and-drop, that looks easy! 10 minute demo!
Answer: a Framework!
(yet another framework, of course)




Struts – reduced lines of code, made apps pretty
complex, created a niche of skilled Struts
mercenaries
WebWork – fixed some of the Struts hassle
SpringMVC – brought powerful AOP concepts
to web dev
Tapestry – JSP? dump it, XML rules!
MVC
WARS




any Web apps in 2006 means seeing a mix of Struts,
Tapestry, Spring MVC, and Webwork (consultant:
which one pays the best?)
the battle rages on, who will win? how can you tell who
won? Trust Craig? Trust Rod? How can a OSS project
define victory?
Converting legacy apps: Struts is dead! long live Struts 2
Action and Struts 2 Shale!!!
How can I possibly pick one for a new project, when
the technology is under attack?
JSF to the rescue






Make Committees, Not War!
get the big players together to solve MVC problems in
a standard way, argue, compromise, repeat... publish
final Spec
Use components, not actions, more like Swing, less like
Struts
Set a standard so we can build derivative products like
IDEs with drag-n-drop ease, without worrying about
change
extensible standard to allow growth (plugins)
and the main objective...
errr... What’s a component?




the JSF spec defines a standard set of
components and relationships
the View layer (e.g. JSP) and the Java code on
the server use these components to interact and
pass data
JSF tree is the current set of components in a
Java object graph
Struts, Webwork, SpringMVC use actions, not
components
typical JSF component tree
View
Form
input
input
combo
command
How does Apache MyFaces work?


jar file for deployment on Tomcat or any J2EE
container – myfaces-all.jar
Controller servlet, XML config file, JSP, a pile
of base classes, and custom tags out the wazoo
(of course! just like all the other frameworks!)
MyFaces architecture
J2EE server
Faces
Servlet
my App
base classes
faces-config.xml
MyFaces Demo








I used: Eclipse, Java5, JBoss 4 (JBossIDE)
Register a user
the Bean: Registration
the view : HTML and JSP
the Action Controller
the web.xml
faces-config.xml
navigation
What is Seam?





Seam is a new product from JBoss, (OSS, free as
in beer and speech)
Founded by Gavin King, Hibernate creator
uses Java5 and EJB3
goal: use the exact same objects for persistence
and rendering the view layer: abolish glue code
and DTO objects
combines MyFaces, EJB3
Seam Demo




the Bean: User EJB3
the view : HTML and JSP
the Action: Register SSB
Seam in the faces-config.xml?
Next for Seam?

Reverse Engineering – make a whole app from a
set of database tables
Facelets




Totally replace JSPs, uses XHTML instead
Integrates tightly with JSF
faster and leaner than JSPs – same idea as
Tapestry
avoids serious JSP / JSF integration issues
Seam architecture
JSP
Facelets
Sun JSF RI
MyFaces
Seam Framework
EJB3
Hibernate3
SQL DB
Tomahawk




Apache’s extended JSF components, ships with
MyFaces
Calendar
Tree
advanced inputText
the Future





continued Component development, similar to
taglib dev with Struts
more tool dev – Eclipse plugins, GUI designers
Facelets general acceptance instead of JSP
Seam innovation from Gavin King, JBoss also
JSR 299 WebBeans just started
Shale? Will Craig McClanahan work on Shale or
just Struts 2 Action (aka Webwork)
Glossary







JSF – JavaServer Faces
JEE5 – the newest Java App Server spec, includes EJB3, JSF etc.
MyFaces – Apache’s JSF impl, completely replaces Sun’s ref impl for JSF
Tomahawk – Apache’s set of components to extend JSF, comes with MyFaces
Facelets – replacement for JSP, interprets XML instead of JSP files to
produce web pages, integrated well with JSF
Seam – JBoss’ framework that works with JSF to provide the glue between
JSF and EJB3 to reduce lines of code, includes MyFaces, Facelets (Gavin
King’s project)
Shale – Apache Struts (Craig McClanahan) framework to provide a better API
for JSF, competes with Seam, needs JDK5, not EJB3
Resources







JavaServer Faces by Hans Bergsten, OReilly
http://java.sun.com/javaee/javaserverfaces/
http://www.coreservlets.com/JSF-Tutorial/
http://www.jboss.com/products/seam
http://docs.jboss.com/seam/reference/en/html/tutorial.html
http://struts.apache.org/struts-shale/index.html
http://www.jsfcentral.com/articles/facelets_1.html
Questions?
contact: Jay Meyer jmeyer@harpoontech.com
discuss: Ideal architecture?
Facelets, MyFaces, Seam, EJB3, JBossAS, MySQL, Ubuntu
Linux?
discuss: worst of breed?
JSP, Struts 1.x, Sun JSF RI, Websphere, Toplink, DB/2,
Windows
Download