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.
1. A button in the status form that changes the URL
2. Part of status form's managed bean
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.
Joined: Sep 09, 2003
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?
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.
An IDE is no substitute for an Intelligent Developer.
Joined: Sep 09, 2003
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.
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.