3

ViewScoped我正在尝试从一个由bean支持的视图中打开一个带有 JSF 视图的新浏览器选项卡(在一个 portlet 中,部署在 Liferay 中) 。使用正常动作重定向会杀死 bean。我已经尝试过这里这里提供的方法,但不幸的是没有成功。

该按钮看起来或多或少像这样:

<p:commandButton value="#{msg.label}" onclick="target='_blank'" 
                 action="#{sessionScopedBean.action(param)}" ajax="false" />

将 移动target='_blank'到 form 属性没有帮助。我已经尝试过返回null并且void没有成功。更改 ajax 以true破坏导航,没有打开新选项卡,但也没有杀死ViewScopedbean。

action方法内容如下所示:

public void action(String param) throws IOException {
   //some business logic

   FacesContext.getCurrentInstance().getExternalContext().redirect("viewName.xhtml");
}

该视图不包含标记处理程序,例如<c:if test="..."><ui:include src="...">。它确实包含一个<ui:repeat id="..." value="#{viewScopedBean.collection}" var="..." varStatus="...">标签,但删除它改变了注意。表格包含在<ui:composition><ui:define>标签中。

我重定向到的视图与 ViewScoped bean 没有任何联系。有任何想法吗?:)

4

1 回答 1

3

视图范围中断,因为您使用的重定向操作基本上是指示客户端在给定 URL 上触发全新的 GET 请求。相反,您应该返回null或有条件地在同一视图void中呈现结果。

也可以看看:


The solution was already given in the links you found: put the data of interest in the flash scope before redirect and obtain them from the flash scope in the bean associated with target view. If this isn't working for you for some reason, an alternative would be to generate an unique key (java.util.UUID maybe?) and store it in the session scope as key associated with some data you'd like to retain in the redirected request,

String key = UUID.randomUUID().toString();
externalContext.getSessionMap().put(key, data);

and then pass that key along as request parameter in the redirect URL

externalContext.redirect("nextview.xhtml?key=" + key);

so that you can in the postconstruct of the bean associated with the target view obtain the data:

String key = externalContext.getRequestParameterMap().get("key");
Data data = (Data) externalContext.getSessionMap().remove(key);
// ...
于 2013-09-03T12:54:27.170 回答