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.
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