If You Know JSF, You Know Portals and Portlets
By: Wesley Hales
June 1st, 2010
• JBoss Portlet Bridge Project Lead
• RedHat’s representative on JSR-301 & 329
• RichFaces contributor & GateIn core dev
• Side projects include: wesleyhales.com, Firefox Anthem
@wesleyhales vimeo.com/wesleyhales
Take Aways
• Understand what a portlet is and does
• Learn how a JSF application maps to the portlet API
• Best practices for working with multiple JSF apps within a portal environment
Portlets of Yesterday
• “... looking for a strong Portal Developer with experience”.
• JSP’s with awkward portlet API mapping
• Yet another lifecycle to learn
Portlets Just Got Easier
• JSF developers are portlet developers (and most don’t even know it)
• With a JSF portlet bridge, you’re not required to learn the underlying portlet development concepts or APIs.
• But there are a few things that are nice to know ;)
Quick Portlet Overview
• Spec driven (168 & 286)
• Rendered markup fragments on a page.
• Different window modes like edit, help, and view
Portlets are...
Portlet UI
Portals & Portlets
• Portals integrate services across organizational boundries. i.e. - SSO, collaboration and social, etc...
• Portlet windows deliver the data to the user and can come from various sources - wars/ears/wsrp.
If you really want to know...
• Servlets vs. Portlets
• Wrapping your head around 2 (or more) requests.
• Portlets generate a page with multiple portlet windows that can be rendered multiple times.
• All links are generated by the portlet api
What is a Bridge, and why do we need one?
• There are many different bridges to handle different web applications.
• Wicket
• Seam
• Spring MVC
• JSF
• Struts
• PHP
Cool Usecases?
• Most larger companies have a need for a portal
• Multiple teams working in parallel
• Blended content with legacy apps
• Communication between 2+ wars on same page
• leverage existing investments
• Allows JSF 1.2, JSF 2, RichFaces, and Seam to run as portlets
• Extensions and components
• Backed by a healthy community, documentation, screencasts, and archetypes
How the Portlet Bridge manages the Faces single
request lifecycle
Portlet Container
Apply Request Values
Restore View
Render
Process Validation
Update Model Values
Invoke Application
Actio
n R
equ
est Faces Engine
JSF Portlet
Ren
der R
equ
est
Reso
urce R
equ
est
Even
t Req
uest
Bridge Request Processing
*See section 5.1 of the Bridge 2.0 spec for full details
Servlet Processing
• Ability to (simultaneously) process incoming faces requests via servlet container
• Good for debugging
JSF 1.2 Portlets
• Add a portlet.xml and the portlet bridge jars to your current JSF application.
• Use the archetype for reference
Working with the portlet API through JSF
• FacesContext.ExternalContext (i.e - dispatch(), encodeActionURL(), getResponse() ...)
• EL Variables - (i.e - portletConfig, renderResponse, portletPreferences, ... )
Environment Based Resolution:
Portlets
Automatic script wrapping (via web.xml)
Supports all Richfaces components (i.e. - upload, push, etc...)
Portlets*Detailed example of Portlet Application Scope: http://vimeo.com/11484018
Simple SSO config between portal and seam app (via components.xml)
Portlet Application Scope
JSF 2.0 Portlets
• JSF 2 is currently available as “Tech Preview”
• Add a portlet.xml and the portlet bridge jars to your current JSF 2 application.
• Use the archetype for reference
Sending Events
• Bridge provides its own BridgeEventHandler
• Standard Event configuration in portlet.xml
• Can receive or send events from any portlet
Portlet Container
Seam Portlet
Event
JSF Portlet
*Detailed example of Sending Events: http://vimeo.com/11484018
Demo
Public Render Parameters
• Simple way of providing a parameter which can be consumed by any portlet
• BridgePublicRenderParameterHandler
• Map parameters to any BackingBean member (via faces-config.xml)
*Full example of working with Render Params here: http://vimeo.com/11484018
Changing Portlet Modes Using Faces Navigation
Rendering Multiple JSF Apps on One Page ?!?
• The bridge takes care of JSF + Portlet namespacing
• Shared custom js will require it’s own NS
• Getting the bridge NS:
Other Need to Knows
• Clearing the view history between modes
• Ajax Error Handling
• Redirecting to an External Page or Resource
bit.ly/9fjktn
Getting Started• Maven Archetypes - bit.ly/9CMKZG
• Eclipse / JBoss Tools support
Getting Involved
• User Forums
• Articles & How Tos
• Jira - Add your enhancement or try to handle some created issues
Useful Links
• http://jboss.org/portletbridge
• http://vimeo.com/wesleyhales/videos
• http://jboss.org/gatein