aspose file tools*
The moose likes JSF and the fly likes JSF read GET Parameters into Backing Bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF read GET Parameters into Backing Bean" Watch "JSF read GET Parameters into Backing Bean" New topic
Author

JSF read GET Parameters into Backing Bean

Klaus Schuster
Ranch Hand

Joined: Feb 10, 2009
Posts: 30
Hi,

I am trying to read in my backing bean the given GET parameters from an URL like:
http://myapp.myserver.com/myjsfpage.xhtml?property=test

I need each call of the page the property, which is set in the URL. My problem: I do only have session as my scope.
So I tried to write an redirect like:
<redirect.xhtml>


My BackingBean looks like this:


Faces config:


I tried to create an Backing Bean with request scope, so that I can easily read the given GET Parameters for redirecting to my final BackingBean => method => property.
Even If I hit the page, it loops, and calls my method without setting the property from the URL.

Is there any better way to handle such parameters?
Thanks
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16243
    
  21

You might want to look at PrettyFaces. It's an add-in that allows you to define bookmarkable URLs for JSF.

One of its benefits is that you don't have to go rooting around inside JSF and HTTP data structures to get the URL parameters - just define their prototypes in the prettyfaces config file and PrettyFaces will inject them into the backing bean for you.


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

Joined: Feb 10, 2009
Posts: 30
thanks for the tipp. What kind of perequisites in terms of frameworks or libraries do I have?
Klaus Schuster
Ranch Hand

Joined: Feb 10, 2009
Posts: 30
thanks for the tipp. What kind of perequisites in terms of frameworks or libraries do I have?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16243
    
  21

Klaus Schuster wrote:thanks for the tipp. What kind of perequisites in terms of frameworks or libraries do I have?


I let Maven handle that. It tells me that ocpsoft-pretty-faces V1.2.3_GA requires Apache commons-digester 1.8, but I think a more formal list of prerequisites is provided on the ocpsoft home page.

The digester is used to compile the pretty-config xml file.
Klaus Schuster
Ranch Hand

Joined: Feb 10, 2009
Posts: 30
is it not possible to use the code shown above?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16243
    
  21

Klaus Schuster wrote:is it not possible to use the code shown above?


Well, apparently not and get the results you want. As to why, I'm not sure. I'd have to do more digging than I can spare time for. Probably something basic, though.

On the other hand, given a choice between a simple injection and complicated framework-dependent code, I like the simple injection myself.
Klaus Schuster
Ranch Hand

Joined: Feb 10, 2009
Posts: 30
Well i found the solution for my code:

I defined on my jsf page an outputText:


my init Method in my BB:


Each time I reload the page, I can use the URL Parameters.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16243
    
  21

Klaus Schuster wrote:
Each time I reload the page, I can use the URL Parameters.


Only if by "reload the page", you mean "request the page by an explicit URL". The normal JSF form edit/review/display cycle won't preserve those parameters - once the view is presented, the postback URL is MUCH uglier. Plus it's a POST, not an HTTP GET.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSF read GET Parameters into Backing Bean