Posts

Showing posts from September, 2009

Calling JSF actions by URL

In JSF 1, there is no provided functionality to invoke an action (by this I mean a java function, not a JSF action invoked by a component). JSF 2 adds functionality to support this, through f:viewParam / f:event and the PreRenderViewEvent . However in JSF 1, you can bind a phase listener to a specific page using the f:phaseListener tag to call the code before the Render Phase. To make sure that the code is only called when the page is access via the url and not from a postback caused by a component you can use the function added in JSF 1.2:  ResponseStateManager.isPostback(FacesContext context) . First off we configure the phase listener in the page (action.xhtml): <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core"> <f:phaselistener binding="#{urlActionBean.listener}" /> Next is the phase listener and action code: public class UrlActionBean { /*...