Parameter Passing / Request Parameters in JSF 2.0

This Blog is a compilation of various methods of passing Request Parameters in JSF (2.0 +)

(1)  f:viewParam

One of the features added in JSF 2.0 is "View Parameters"; Simply speaking it allows adding "Query string" or "Request Parameter" to the intended URL. One of the benefits is that it facilitates URL bookmarking.

In JSF 2.0 "View Parameters" is implemented by UIViewParameter. This class extends UIInput (jee6 api docs) and hence inherits features like Converter's, Validator's, full JSF lifecycle support, value binding and listeners.

"View Parameters" are defined in a Facelet page using <f:viewParam> tag. This tag is used inside metadata facet of a view <f:metadata>, which causes a UIViewParameter to be attached as metadata for the current view.
(source index.xhtml)

The above tag/config tells JSF engine to bind the value of "day" request parameter from the url (the url would be something like http://hostname/index.xhtml?day=Sunday) to the "day" property of "viewParamManagedBean". As mentioned above, "UIViewParameter" extends "UIInput", so it inherits all attributes like "required", when required="true", if the url does not include the required param, the page is not displayed.

This example attaches an component event listener (source page2.xhtml)

 Its noteworthy that "setDay()" method of BackingBean is called in update model value phase, so its not available in @PostConstruct and so as a result to do initialization/preloading based on the set value, you need event listener as described above.

You can also include the view params in the links by simply using attribute includeViewParams="true"

You can also use "includeViewParams" in backing bean to include viewParams in the navigation link as follows

(2) f:param

"View Params" is a good way of passing along parameters i.e. parameter that your page receives. However to send a parameter from a facelet to backing bean, or that matter to any other facelet you can use following approach:

and in the backing bean declare a @ManagedProperty and link its value to the request parameter by

To send a parameter to another JSF page

In the managed bean of page2, you can declare a managed property (as shown in example above) and capture value of passed in parameter.

(3) Method Expression

You can send parameter as an argument to an action method i.e. bean.actionMethod(Type param1, Type param2)
 Here is a sample JSF code with datatable displaying day's of a week, and a select button in each row. The action method is passed an argument, which is the declared variable of the datatable:

Backing Bean:

When you include a f:param tag in “h:commandButton” or "h:commandLink", the parameter is turned into request parameter,  
which in the backing bean can be retrieved as

(4) f:Attribute

Parameter/Values can be passed to an actionListener method (of a commandUI) using f:attribute
In JSF page

In the Backing Bean capture the value using

One Could also use f:Attribute to pass an attribute to an component. for e.g.
 <h:outputLabel for="sportsPer" value="Do You Play Tennis:" />
  <h:selectOneRadio id="sportsPer" value="#{someBackingBeanView.likesTennis}" validator="#{someBackingBeanView.validatePlayer}">
    <f:selectItem itemLabel="No" itemValue="N" />
    <f:selectItem itemLabel="Yes" itemValue="Y" />
    <f:attribute name="clubNameAttr" value="#{clubName.submittedValue}" />
Where "clubNameAttr" is the bind id of a form field whose value is required in the validator method (multi/complex form field validator).
<h:inputText id="clubNameId" binding="clubName" value=" #{someBackingBeanView.clubName}"/>
Now in the validator method, one can get the value of attribute "clubNameAttr"

public void validatePlayer(FacesContext context, UIComponent component, Object value) throws ValidatorException {
String clubNameAttr = (String)component.getAttributes().get("clubNameAttr");
//do something ...

(5) f:setPropertyActionListener

Parameter/Values can also be passed to an actionListener method (of a commandUI) using f:setPropertyActionListener
In JSF page

 In the Backing Bean

One thing to note is that the setDay() is called after the listener method (listenerToGetAttributes(..)) completes. So if the scope of "DayOfWeekManagedBean" is higher than Request, then you will see that the value of "day" in listener method is of the previously clicked button and NOT the current (because listeners are invoked in the sequence they are defined).

(6) JSTL tag <c:set>

There is no equivalent tag for <c:set>in JSF, f:param is NOT the same. This one comes in handy when f:param is not available in backing bean; for example when passing a parameter to <ui:include> tag. If you add <f:param> for example <f:param  name="activeIndex" value="0"/>, the value will be available in the included JSF page as #{activeIndex}, but NOT in the constructor of the backing bean of the included page. In such scenario, one can use <c:set>

In the Backing Bean capture the value using

Prasanna Bhale


  1. This page really helps! Thanks a lot!

  2. ThankQ very much.Really very useful..

  3. Great article, keep on good work, thnx

  4. Really, really great article.
    You have answered one of the most basic questions about JSF that is no where to be found!
    Somehow this is a very grave issue in JSF.

  5. very nice , exelent !

  6. great and clear tutorial. After hours of reading I finally understood and could actually do something!

  7. Java Online Training Java Online Training Java Online Training Java Online Training Java Online Training Java Online Training

    Hibernate Online Training Hibernate Online Training Spring Online Training Spring Online Training Spring Batch Training Online Spring Batch Training Online

  8. Excellent…Amazing…. I’m satisfied to find so many helpful information here within the put up,for latest php jobs in hyderabad. we want work out extra strategies in this regard, thanks for sharing.

  9. Very nice!; which use each case of use?. And why?. Thanks so much!.


  10. شركة الصفرات للتنظيف بالرياض
    Cleaning is one of the priorities of life that is indispensable and must be taken care of permanently on availability in the place So Safrat cleaning company in Riyadh to provide a distinctive set of detergents strong and safe and able to handle all types of stains and remove easily and without the need to bother and hardship cleaningشركة-الصفرات-للتنظيف-بالرياض/

    شركة الصفرات لمكافحة الحشرات بالرياض
    Al Safrat Pest Control Company in Riyadh provides a range of insecticides that are capable of completely eradicating all types of insects present in the place. All pesticides are completely safe for health and can be treated in the presence of family members normally through the best pricesشركة-الصفرات-لمكافحة-الحشرات-بالرياض/

    شركة الصفرات لنقل الاثاث بالرياض
    Al Safarat Furniture Company in Riyadh offers a very distinctive collection of cars that are used to transport various pieces of furniture and equipped inside to receive all the pieces to be transported properly without any impact on the otherشركة-الصفرات-لنقل-الاثاث-بالرياض/

    شركة الصفرات لتنظيف الخزانات بالرياض
    Al-Safrat Company for cleaning tanks in Riyadh advises its customers with a number of different advice to ensure the safety of the tank and the health of the customer in the first place
    And on top of these tips
    Do not leave the tank filled with water if not in useشركة-الصفرات-لتنظيف-الخزانات-بالرياض/


  11. شركة تنظيف بالمدينة
    A cleaning company in Madinah provides a very large range of the best types of detergents that are completely safe for health and can be dealt with in the presence of family members without affecting them and has a very distinctive result

    شركة تنظيف بينبع
    A cleaning company recommends that the house should be constantly cleaned and ventilated as there is no room for the spread of unpleasant odors or the spread of various insects. A cleaning company recommends exposing all places in the house to direct sunlight and heat in order to kill any delicate insects in the place

    شركة نقل اثاث بينبع
    Moving furniture is not easy to work on without any problem so a furniture transfer company in Yanbu provides a distinguished group of carpenters who are able to dismantle and install all kinds of furniture to be transferred properly