• Post Reply Bookmark Topic Watch Topic
  • New Topic

Obtaining Page URL from Managed bean  RSS feed

 
Abiodun Adisa
Ranch Hand
Posts: 495
  • Mark post as helpful
  • send pies
  • 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?
 
Ketan Jambhekar
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • 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.
 
Tim Holloway
Bartender
Posts: 18715
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!