开发者

JavaServer Faces navigation

I have an application using JSF, which has a navigation bug. The homepage, which is index.jsp (however I have an index.faces file -- and this file is listed in the welcome list) has a form on it. When the form is submitted, a backing bean is called, which creates a new view and sets it as 开发者_运维技巧the current view. This view is the next page in the web site flow.

What's happening is this: the first time a user comes to the site (or if the browser history is cleared), the form submit stays on the same page. It's not until the second time the form is submitted that the following page is shown.

On the first click, the URL changes from http://companyconnector.com/ to http://companyconnector.com/index.faces;jsessionid=...

Any ideas?


That's not a bug, that's how JSF fundamentally works: the input form does a POST requst to the JSF view that rendered it, and the action method's outcome, together with the navigation rules, determines which view is then shown. However, this flexibility means that navigation cannot be immediately reflected in the URL, because the browser that submits the request does not know which view (=URL) the application will decide to show. After all, even if there is no complex logic determining the next view, there can always be validation errors causing the current one to be shown again.

There are ways around this, but they have limitations:

  • You can add a <redirect/> to every navigation rule, but this will slow down the application
  • In JSF 2, you can use view parameters, but this is really only meant for "bookmarkable URLs" on specific pages, not for general usage. But it can be abused to almost get there.


Have you tried changing the scope of the backing bean from session scope to request scope? Which version of JSF is this anyway?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜