Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSF read GET Parameters into Backing Bean

 
Klaus Schuster
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18154
52
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Klaus Schuster
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the tipp. What kind of perequisites in terms of frameworks or libraries do I have?
 
Klaus Schuster
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the tipp. What kind of perequisites in terms of frameworks or libraries do I have?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18154
52
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is it not possible to use the code shown above?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18154
52
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18154
52
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic