aspose file tools*
The moose likes JSF and the fly likes Getting GET / POST variable values from a JSF webpage Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Getting GET / POST variable values from a JSF webpage" Watch "Getting GET / POST variable values from a JSF webpage" New topic
Author

Getting GET / POST variable values from a JSF webpage

David Brossard
Ranch Hand

Joined: Jun 03, 2004
Posts: 109
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?


No matter what they say in Ohio, we're still first in flight!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16137
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
David Brossard
Ranch Hand

Joined: Jun 03, 2004
Posts: 109
Thanks so much, that explains why there was so little on the topic on the net.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting GET / POST variable values from a JSF webpage