jsf 2.0 @ViewScoped重定向(导航)到target ="_ blank" [英] jsf 2.0 @ViewScoped redirect (navigation) to target="_blank"

查看:171
本文介绍了jsf 2.0 @ViewScoped重定向(导航)到target ="_ blank"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本相同的问题>这里

如何在我重定向到其他浏览器标签的页面上保留ViewScoped bean:

How do I retain a ViewScoped bean on the page from which I redirect to a different browser tab:

firstPage.xhtml:

firstPage.xhtml:

<h:commandLink action="#{controller.redirect}" value="#{bean.value} target="_blank"/>

当重定向/导航完成了对其他bean的初始化后,它将在此过程中销毁此#{bean}.在重定向的代码中,我什至没有使用#{bean}.这曾经与

When redirect/navigation finishes with initializing the other beans, it destroys this #{bean} in the process. In the redirected code I am not even using #{bean}. This used to work with

<a4j:keepAlive>

这是我当前的设置. 豆类:

Here's my current setup. bean class:

@ViewScoped
public class Bean{ 
    @PreDestroy
    public void onDestroy(){ // being destroyed when I don't want to }
}

faces-config:

faces-config:

<navigation-rule>
  <from-view-id>/firstPage.xhtml</from-view-id>
    <navigation-case>
      <from-outcome>redirect</from-outcome>
      <to-view-id>/secondPage.xhtml</to-view-id>
  </navigation-case>
</navigation-rule>

推荐答案

您需要按照Luiggi的建议进行操作,并将数据临时存储在会话中,或者通过查询参数将数据(或足以重新获取数据的键)传递给目标视图.即使您没有重定向和/或定位新的窗口/标签,也是如此.

You need to do as Luiggi suggested and store data temporarily in the session or pass the data (or keys sufficient to re-fetch the data) via query parameters to the target view. This is the case even if you weren’t redirecting and/or targeting a new window/tab.

视图范围很奇怪.只要用户停留在同一视图上,它就存在.当JSF看到该视图已被导航离开时,它将自动销毁该视图作用域内的所有bean.

View scope is strange. It exists only as long as the user stays on the same view. When JSF sees that the view has been navigated away from, it will automatically destroy any beans scoped to that view.

有两种方法可以导航到不同的视图.第一个是非面部请求,例如来自h:linkh:button的请求.在这种情况下,先前的视图无法还原,因此JSF不会知道有任何视图范围的bean需要销毁.第二个是面孔请求,例如来自h:commandLinkh:commandButton的请求,该请求返回除voidnull之外的其他内容.在这种情况下,将存在视图的回发,将其还原以处理操作.如果该操作的结果是离开该视图(是否重定向),则作用于该视图的所有bean都将被销毁.

There are two ways that you can navigate to a different view. The first is a non-faces request, such as from h:link or h:button. In this case, the previous view is not being restored so JSF wouldn't know that there are any view-scoped beans to destroy. The second is a faces request, such as from h:commandLink or h:commandButton, that returns something other than void or null. In this case, there is a postback to the view, which is restored in order to process the action. If the result of that action is to navigate away from that view, redirect or not, any beans scoped to that view will be destroyed.

在内部,视图作用域本质上是具有某些内置语义的会话作用域,用于清除旧"数据.如果用户没有在一个以上的窗口/标签中打开该应用程序,而仅使用该应用程序内提供的导航功能(即,不是浏览器的后退/前进按钮),这实际上会很好地起作用.但是,由于我们正在谈论针对Web浏览器,因此,我认为视图范围非常无用(唯一的例外是可以控制目标浏览器并完全禁用后退/前进/重新加载/定位的情况,但它并没有听起来好像你处在那种环境中.)

Under the hood, view scope is essentially session scope with some built-in semantics for cleaning up "old" data. This actually works well if users don’t open the application in more than one window/tab and only use navigation provided within the application (i.e., not the browser back/forward buttons). However, since we’re talking about targeting web browsers, view scope is, in my opinion, pretty useless (with the only exception being cases where you can control the target browser and completely disable back/forward/reload/location, but it doesn’t sound like you’re in that kind of environment).

这篇关于jsf 2.0 @ViewScoped重定向(导航)到target ="_ blank"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆