• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Why does URL change if REDIRECT not specified?

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In order to get to the menu form I enter http://localhost:8080/myapp/pages/menu.jsf into the browser. When the menu form comes up, I click on a button that takes me to the status form. After getting to the status form, the URL remains the same i.e http://localhost:8080/myapp/pages/menu.jsf However, as soon as I click any button in the status form, the URL changes (to http://localhost:8080/myapp/pages/status.jsf ). As a result of this, all the components that have been programmatically set to rendered=false become rendered when the status form is rendered after submission.

Even though I did not specify a redirect, the changing of the URL gives the impression that a redirect takes place after the status form is submitted. Can anyone please tell me why this is happening and how I can stop it. I am using MyFaces 2.0 on Tomcat 7 The managed bean for status form is in the request scope.

Thanks.


1. A button in the status form that changes the URL
====================================================


2. Part of status form's managed bean
====================================


2. Faces Config
================

 
Ranch Hand
Posts: 200
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In looking at your navigation rules I don't see the desired behavior configured.

You need navigation rules to take you from menu to status, and your action method needs to return the appropriate String to trigger the navigation rule.
 
Tokunbo Oke
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guy deLyonesse, thanks for your response.

I do not have any problem navigating from the menu form to the status form, though. This is because I am using JSF 2.0'S implicit navigation, which is an alternative to declaring navigation rules in faces-config.xml. The only thing I need help with is understanding why the URL changes when I submit the status form and I am not redirecting?

Thanks.
 
Saloon Keeper
Posts: 28756
211
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
You do not own the URL in JSF. JSF does. And JSF, unlike most web frameworks, uses the URL less as an absolute resource path than it does as a session handle, so the actual displayed text is not necessarily an indication of the underlying resource(s) used to build the View (page).

You are not doing a redirect. A redirect is a completely separate operation and actually should be avoided due to the extra overhead required.

The reason you're losing your "rendered" settings has nothing to do with the URL. It has to do with the fact that your backing bean is in Request scope.

Meaning that once the page has been displayed, the original backing bean is destroyed and when you then postback the form, a whole new un-initialized backing bean will be created.

JSF can't do much with request-scope objects because of this issue. You need longer-lived scopes. Originally, this meant Session or Application scope, but JSF2 added a special scope called View scope that's usually sufficient for data entry forms.
 
Tokunbo Oke
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tim Holloway, thanks for your response. You are absolutely correct my rendered setting are lost because of the fact that the backing bean is request scoped.

Regarding the visible URL that changes when I am not using redirect to navigate to another page (or even to the same page); are you saying this is a normal behaviour of JSF? If yes, please give me a link to any document that sheds more light on why this is the case. I am just curious to know why it is designed to work this way, as this is different from what I understand about forwarding and redirecting.

Thanks.
 
Tim Holloway
Saloon Keeper
Posts: 28756
211
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
I don't recall ever having seen anything written up on the URL situation but it basically has to do with the fact that JSF makes extensive use of postbacks.

Most web frameworks display a form and they're done with it. In JSF, the same form will be repeatedly redisplayed (thanks to postbacks) until you've satisfied all the validation constraints and made all the error messages go away.

HTTP does not send out a URL when it sends out a page. In fact, it really can't since a given page may have dozens of different URLs coded on it for things like menus, links to other places, click-through adds and so forth. The URL in the navigation bar is simply the URL being used to do the next server request.

You can force the URL in the navigation bar to reflect the target resources more accurately using the "redirect" navigation directive - and in cases of secured pages, you usually have to. But that requires a literal redirect, which is extra overhead. So for best performance, it's better not to unless you absolutely must.
 
Tokunbo Oke
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Noted, thanks a lot.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic