• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to get current external URL *on forwarded page*

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am seeing something, maybe you can explain this. I think it has
something to do with "external" context..

When I enter my JSF web app, the browser address bar says
"http://myserver.com/jsfapp/index.jsf" for example. I click around in
it, and the address bar doesn't change, even though I am on a
different page, say http://myserver.com/jsfapp/newpage.jsp. (like in
servlet forwarding)

When I am at this newpage.jsp, it has a header tag, and inside the
header tag java class I do this:


then s is "http://myserver.com/jsfapp/index.jsf"

If I do this:



then s is "http://myserver.com/jsfapp/newpage.jsp"

but I want s to be "http://myserver.com/jsfapp/newpage.jsf"

How do I do this?

THANKS

> >> I am inside a JSP tag java file and I want to know the URL of the
> >> request, so I use request.getRequestURL(). But it returns
> >> http://myserver.com/jspapp/myfile.jsp instead of
> >> http://myserver.com/jspapp/myfile.faces or http://myserver.com/myfile.jsf.
> >> In other words, I want the request entered FOR THAT PAGE, not the one
> >> entered by the user in the address bar a few clicks back.
 
Saloon Keeper
Posts: 27752
196
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
JSF is different from other webapp frameworks. The URL isn't so much a direct path to functionality as it is a handle to an ongoing conversation. That's why it doesn't change when you'd like it to.

That can be really irritating, however, when you want something you can bookmark or email to a friend.

A good solution is to use the PrettyFaces package to give you the ability to use direct URLs. It's quite easy to install and configure.

That's half the battle. The other half isn't as obvious - your problem. How do you get the bookmarkable URL presented in the user's browser?

Answer: a little magic in the faces-config file:



The magic is the "redirect" element. That basically causes the request to get routed out and back in again under the external URL you want, unlike the usual action, where the system just does a direct internal transfer to the destination.

It also confers another benefit. The J2EE container security framework doesn't understand the peculiarities of JSF - it maps security against the URL. By using the <redirect> element, the request gets resubmitted under the "proper" URL and the container security screen will be properly applied.
 
Hey! You're stepping on my hand! Help me tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic