3

1) Is it a good practice to use get http variable in JSF? it seems that it tries to avoid that.

2) Here is what I want to do: on the first page, I have a list of links, if you click on a link, you have a page with other links etc. like a tree. I would like the user to be able to access the 3rd depth (for example) without starting from the top level (via a link with the related object ID in a get variable for instance).

so my question is: How to set a get http variable from the managed bean?

To get it, this post is quite clear : Get http variable JSF

3) Of course, if you have another solution, feel free to share it.

Cœur
  • 32,421
  • 21
  • 173
  • 232
dyesdyes
  • 1,075
  • 2
  • 18
  • 38

1 Answers1

6

There's no means of a good/bad practice as to using GET requests in JSF. If the business requirement mandates using a GET request, then just use it. However, there's some history: in JSF 1.x there was no facility which eases applying/converting/validating GET parameters. You'd have to do it all yourself by traversing the ExternalContext#getRequestParameterMap() and/or by setting managed properties with #{param} and write all the conversion/validation boilerplate yourself. Using POST was then much easier (read: less code) and this might have caused the myth that GET is "bad" in JSF.

Since JSF 2.0, the new <f:viewParam> tag was introduced which should make it all a breeze. It's like the <h:inputText>, including conversion/validation, but then for request parameters.

Note that it's actually a bad practice to use POST for pure page-to-page navigation, which was more than often done in JSF 1.x. It resulted in non-bookmarkable and non-SEO-friendly requests.

See also

Community
  • 1
  • 1
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
  • Thanks! Those posts are perfect! It's difficult to find the right post with "get variable" as keyword. – dyesdyes Jan 16 '13 at 16:58
  • 2
    Most of those posts can be found in [our JSF wiki page](http://stackoverflow.com/tags/jsf/info) (you can get there by hovering the `[jsf]` tag below the question and then clicking the *info* link in that black popbox). Also, you can get the most interesting answers/practices/etc when you browse [the "FAQ" tab](http://stackoverflow.com/questions/tagged/jsf?sort=faq) of the `[jsf]` tag (the default is "Active" tab) – BalusC Jan 16 '13 at 17:00