0

Okay we have a single - sign - on and the user will likely enter www.blabla.com/AppName/ to reach our site. We then define a welcome site, use a phaselistener to check:

is user trying to access the welcome site? yes -> try to login - works? yes -> get user roles -> forward to the appropriate site for this specific user.

E.g. user niceBelly goes to page /somewhere/in/many/folders/beer.jsf and user barbie goes to /breasts/pink.jsf a redirect is in this application not possible for some reasons.

the result is that when reaching e.g. page pink.jsf the address bar still shows blablaba.com/AppName/ clicking the first link will result in the browser using the form address as new URL e.g. on welcome.jsf i navigate to coolstuff.jsf. On the page coolstuff i now have the url of the last form, e.g. welcome.jsf. Then on cool stuff i click a link, and get coolstuff on the next page as url, and so on.

Is there a way to solve this / work around it?

animuson
  • 53,861
  • 28
  • 137
  • 147
Toskan
  • 13,911
  • 14
  • 95
  • 185

1 Answers1

3

Given the symptoms, you are actually not redirecting the requests, but you are actually forwarding the requests. A real redirect will take place when you call

externalContext.redirect(url);

in JSF context, or when you add

<redirect />

to the navigation case. All other ways are effectively forwards. As per the symptoms, you're using commandlinks instead of outputlinks to navigate to other page. Commandlinks will submit a POST request to current URL and JSF will under the covers use RequestDispatcher to set the destination of the request/response when the navigation case doesn't contain <redirect />. A forward does not instruct the browser to fire a new GET request on the destination URL and hence the URL in browser address bar does not change. A real redirect will do exactly that.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • you are correct... I wrote redirect and meant forward. The reason I forwarded was because - first of all - it doesn't work with redirect :-) But let's assume I somehow manage to get that business rolling, is there a way to translate the navigation-case outcome to the actual correct page redirect? The problem isn't a "if login then welcome" it's more of a "if login somelogic -> outcome" – Toskan Apr 01 '11 at 14:28
  • Add `` to navigation case in `faces-config.xml` and do not use commandlinks (POST) for plain page-to-page navigation, just use outputlinks (GET). If you need to do some business stuff/preloading on a GET request, just do the job in constructor or postconstruct of the managed bean. This is all much easier when you're on JSF 2.0. It supports for example a `` which translates an outcome to a real URL. – BalusC Apr 01 '11 at 14:31