ApacheCon EU 2006 - Apache MyFaces
Notes from "Introduction to Apache MyFaces" by Matthias Wessendorf, et al
Introduction to JSF
- Framework for Java Web Development
- JSF is a standard
- Easier than JSP/servlets: no need to look up objects
- Plain Old Java Objects
- Managed bean facility "little bit like spring but more basic"
- JSR 127, 252 --> 2004/2005
- JSF 2.0: AJAX, more UI... 2006?
- Many IDE's, 3rd party components
- Implementations: Sun (RI) or Apache MyFaces, plus some others
Introduction to MyFaces
- UI components similar to Swing
- HTML renderkit (or WML / ...)
- component oriented + even driven
- bind backing bean to JSF component
- Server side validation, client side is upcoming
- 1.1.4 is current stable release, spec 1.1 compliant
- JSF API: javax.faces.**
- JSF Spec: org.apache.myfaces.**
- Structure: Core (API + runtime) + components on top of it
- There's portlet support
JSF lifecycle
- restore view
- apply request values
- conversion & validation (request data stored in component)
- update model (call setters, write into backing beans)
- invoke application (process beans, do database stuff)
- render response
there's a shortcut between validation and response rendering
JSF Hello World
- Best practice: NO HTML in JSF files (=JSP file)
- attach bean properties in JSF file
- two way framework: presents bean properties, and writes them back bind to value binding (bean property) or method binding (bean method call)
- method returns a string
- faces-config.xml + managed bean + JSP file
- faces-config.xml defines what to do when what response is returned by method
Internals
- ExtensionsFilter: in web.xml,
MyFaces in Action (Tomahawk)
- use value attribute for every component to pass in data
- default components are available
- example: calendar component: javascript popup or static html
- example: upload component
- example: tree component
- facets define layout
- setup tabbed panels
Custom validators available
- regexp
- equal (passwords)
- etc
Presentation
- Use Tiles for page composition (reusable page components)
Application transaction
- By default, lifetime of bean is bound to the user session
- This causes problems when having multiple windows open
- New scope: conversation scope