35

I believe there are 2 ways to get the parameters from the URL in JSF.

One being in the bean:

Map<String, String> params =FacesContext.getCurrentInstance().
                   getExternalContext().getRequestParameterMap();
String parameterOne = params.get("parameterOne");

and the other one being in the facelets page

<f:metadata>
    <f:viewParam name="parameterOne" value="#{bean.parameterOne}"/>
</f:metadata>

Obviously the latter one will require a field in the class and getter / setter for it.

Besides that, what are the differences between these 2 different approaches? Which one should be preferred?

Koray Tugay
  • 22,894
  • 45
  • 188
  • 319
  • Pretty neat article on a disadvantage of `` http://jdevelopment.nl/stateless-stateful-jsf-view-parameters/ – Andy Jul 27 '13 at 01:04
  • @Andy: which is solved by OmniFaces `` (from the very same author as the article you linked there). – BalusC Jul 27 '13 at 03:20
  • 1
    @BalusC Yes, I actually found this in one of your [blog entries](http://balusc.blogspot.com/2012/03/stateless-view-parameter.html). I thought OP might like. Heck, I learned about this myself just a few hours ago. – Andy Jul 27 '13 at 04:06
  • Set param in view associating with bean attribute, take a look http://stackoverflow.com/questions/13495797/how-to-get-request-parameters-from-view-scoped-jsf-bean – Diogo Alves Jan 27 '15 at 14:51

1 Answers1

54

I think this may help: Get Request and Session Parameters and Attributes from JSF pages

In fact, there should be a query:

<h:outputText value="#{param['id']}" />
Community
  • 1
  • 1
Christian Kuetbach
  • 15,850
  • 5
  • 43
  • 79