Win a copy of Pipeline as Code this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Obtaining Page URL from Managed bean

 
Ranch Hand
Posts: 495
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please is it possible to obtain the URL of the current page a user is viewing from a managed Bean (Either from FacesContext) or any other means?
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
i am not sure if there is a direct method to get it, there could be one but i am not aware of it. But you can get it in the following way

Context Path :


and append the remaining url using


You might want to replace the suffix of the file name depending on your application.

Ketan.
 
Saloon Keeper
Posts: 23414
159
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's actually not good practice. Manage Beans are ideally simple JavaBeans and therefore shouldn't be aware of the framework - including whether they're running under JSF or even in a web application at all.

You can break out of the box by chasing uphill from the FacesContext, but as I've mentioned in other posts on this forum, javabeans are best employed as injection targets, not as items that go out and grab info.

Ignoring ideology, however, there's another issue. JSF isn't directly tied to the URL. Once you start talking in a JSF conversation, an anchor point gets established, and it's the anchor point that's referenced in the URLS for JSF page actions, not an explicit command a la Struts. So knowing the user's last submitted URL may not be a reliable indicator what what's going on or what you should be doing.
 
For my next feat, I will require a volunteer from the audience! Perhaps this tiny ad?
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic