A very FAQ is people that want to be able to run code -- or more specifically JSF actions -- on the loading of a JSF page (on the server -- not JavaScript).

There is nothing built into JSF that allows one to do this, but the framework allows something to be built. Three projects are already implement that give this functionality. They are:

  1. jsf-comp on-load - Simple component with little dependencies

  2. JBoss Seam - Robust EJB3 targeted JSF framework from JBoss

  3. Shale View Controller - Medium weight JSF framework

  4. Apache MyFaces Orchestra - Robust framework which helps dealing with JPA/conversations

  5. PrettyFaces URL rewriter - Lightweight URL rewriting framework

JSF Comp

The jsf-comp on-load is your best bet if you want a light-weight solution. It comes with no baggage. It uses standard JSF navigation rules based one outcomes and leverages XML configuration files to specify which actions to run based on which pages.

JBoss Seam

The JBoss Seam library uses pages.xml to configure what actions to run when a page is loaded. It is very similar in implementation to JSF-comp's project. It also comes with a lot of other JSF functionality that you may find interesting.

Shale

The Shale View Controller is not as heavy as JBoss Seam, but is still much heavier than jsf-comp's on-load. Unlike the other two, it uses Java class naming conventions to bind java code to a page view. Due to this reason, you cannot use the same code for two pages without a bit of tweaking. It also does not support JSF navigation rules, you have to hand code this in the handling bean if you want to navigate to a new page. It does provide functionality beyond just an "on-load" though.

Orchestra

The Orchestra View Controller seamlessly integrates in many JSF environments. Beside the naming convention which is similar to Shale it supports also configuring the viewIds a bean is responsible for using annotations. Compared to Shale only the most important events (InitView, PreProcess, PreRenderView) are supported. It requires Spring and you have to configure your managed-beans there, which is a VERY good idea anyway.

PrettyFaces

The PrettyFaces extension is a lightweight URL mapping tool which has the ability to execute multiple actions on page request, dynamically render a view based on runtime conditions, handle query parameters, as well as create bookmarkable URLs for your JSF views. It enhances and integrates into JSF navigation without changing standard behavior. Configuration takes place in a straight-forward XML file.

Execute_action_on_page_load (last edited 2009-09-20 23:00:38 by localhost)