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:
jsf-comp on-load - Simple component with little dependencies
JBoss Seam - Robust EJB3 targeted JSF framework from JBoss
Shale View Controller - Medium weight JSF framework
Apache MyFaces Orchestra - Robust framework which helps dealing with JPA/conversations
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.
Note: If you are using JBoss Seam you cannot use it due to Seam configuration conflicts.
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.