This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting GET / POST variable values from a JSF webpage

 
David Brossard
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am trying to get the value of a GET variable directly inside my webpage. Something similar to what can be done in JSP or PHP where you can say:

$_GET["some_variable"] (PHP)

The idea is that for some very simple cases you do not want to use a backing bean. Imagine I have a JSF webpage where the background color can be set via the GET variable

mypage.jsf?color=XXX

Or is this a breach of good design / pattern use? If so how would you handle the problem?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18165
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a breach of good usage. That's because JSF uses postbacks. Unlike traditional techniques, in JSF, the same View may go back and forth between client and server multiple times, since one of JSF's primary functions is to support forms with validation. Although an HTTP GET may pull the form up initially, subsequent requests will employ HTTP post. And, just to further confuse things, the URL used (and displayed in the browser navigation control) may not always match the resource name of the View being displayed.

If you want to set a background color and keep that color while all this is happening, your best bet would be to make it a property of a backing bean. If you expect to reach this JSF page from another JSF page, you pretty much HAVE to do that, since JSF does its navigation based on beans, not on URLs and doesn't employ HTTP GET for navigation.
 
David Brossard
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks so much, that explains why there was so little on the topic on the net.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic