JSF 中的浏览器刷新处理
有没有办法可以在 JSF 2.0 应用程序中处理浏览器刷新事件,以便在浏览器刷新页面时将用户导航到欢迎页面? 这引出了另一个问题:如何在托管 bean 中进行页面导航?
干杯,
Is there a way i can handle browser refreshes event inside my JSF 2.0 application so that the user be navigated to the welcome page when a browser refreshes the page?
and that leads me to another question of how to make page navigation inside managed bean?
Cheers,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用单个视图,在其中有条件地渲染包含内容。
使 bean 视图范围化并使用带有
的命令链接来更改包含的页面。如果您在 bean 的(后)构建期间将欢迎页面设置为默认包含页面,则新的 GET 请求将始终显示欢迎页面。唯一的缺点是这些页面不再可添加书签,但鉴于此特定的功能要求,这似乎不是一个主要问题。
Use a single view wherein you conditionally render includes.
Make the bean view scoped and use commandlinks with
<f:ajax>
to change the included page.If you set the welcome page as default include page during bean's (post)construction, then a fresh new GET request will always show the welcome page. The only disadvantage is that those pages are not bookmarkable anymore, but that doesn't seem to be a major concern given this particular functional requirement.
并不真地。
http 协议或 jsf 中没有任何内容。
您可以找到一些“黑客”(对您的请求进行编号),但我认为这最多会很复杂。
如果客户问我类似的问题,我会让他们为该功能支付很多费用,但没有太多的保证。对我来说这似乎是一个不切实际的要求;-)
Not really.
There is nothing for that in http protocol or in jsf.
You could find some "hack" (numbering your requests), but I think it would be complicated at best.
If a client asked me something like it, I'd let it pay a lot for the feature, without too much guarantees. It looks like an unrealistic requirement to me ;-)
我使用下一种方法解决了重新加载页面问题。
RENDER_RESPONSE
阶段的阶段侦听器
已创建NavigateHomePage
。在需要浏览器重新加载的每个页面上,应导航到“主页”,并添加
f:phaseListener
和type = "my.NavigateHomePage"
。afterPhase
方法中的NavigateHomePage
定义当前页面名称(来自request
路径)并将其存储在session
中。beforePhase
方法中的NavigateHomePage
定义当前页面名称(来自request
路径),从session
获取上一个页面名称,并获取请求方法
。如果当前页面名称等于上一个页面名称,并且请求方法
是GET
并且当前页面不是“主页”,则重定向到“主页”完成。限制是,对于此类页面(浏览器重新加载导航到“主页”),不应有指向其自身的链接(通过
GET
)。要将阶段侦听器包含到页面中,请在下一个页面中添加:
Phase Listener
代码如下:I solved reloading page issue using next approach.
Phase listener
for phaseRENDER_RESPONSE
is createdNavigateHomePage
.On every page which requires browser reloading should navigate to "Home page" is added
f:phaseListener
withtype = "my.NavigateHomePage"
.NavigateHomePage
in methodafterPhase
defines current page name (fromrequest
path) and stores it insession
.NavigateHomePage
in methodbeforePhase
defines current page name (fromrequest
path), takes previous page name fromsession
and takesrequest method
. If current page name equals to previous page name andrequest method
isGET
and current page is not "Home page" then redirect to "Home page" is done.The limitation is that for such pages (browser reloading of which navigates to "Home page") there should not be links (via
GET
) to itself.To include phase listener to page add in page next:
Phase listener
code is next: