Jsf ExternalContext#redirect(),includeDevicewParams=true
使用字符串形式的货币列表,如下所示Jsf ExternalContext#redirect(),includeDevicewParams=true,jsf,redirect,primefaces,viewparams,Jsf,Redirect,Primefaces,Viewparams,使用字符串形式的货币列表,如下所示 <p:selectOneMenu id="currency" value="#{currencyRateBean.currency}" onchange="changeCurrency([{name: 'currency', value: this.value}]);"> <f:selectItems var="row" val
<p:selectOneMenu id="currency"
value="#{currencyRateBean.currency}"
onchange="changeCurrency([{name: 'currency', value: this.value}]);">
<f:selectItems var="row"
value="#{currencyBean.currencies}"
itemLabel="#{row}"
itemValue="#{row}"/>
</p:selectOneMenu>
然后,在上面的操作方法currencyAction()
中,将提供的货币值设置为另一个会话范围内的托管beanCurrencyRateBean
,最后基于当前值viewId
以及重要的includeViewParams=true
进行重定向
现在,当
#{currencycratebean.currences}
被更改为具有复合对象的列表时,故事发生了变化,到目前为止,该列表一直是字符串列表
以下场景不适用于重要的includeViewParams=true
<p:selectOneMenu value="#{currencyRateBean.currencyHolder}">
<f:selectItems var="row" value="#{currencyBean.currencies}"
itemLabel="#{row.currency}"
itemValue="#{row}"/>
<p:ajax event="change"
listener="#{currency.currencyAction}"
partialSubmit="true"
process="@this"
update="@none"/>
</p:selectOneMenu>
添加的includeViewParams=true
仅用于装饰。这是行不通的
由于
中的侦听器
无法根据
的操作
所做的导航案例结果进行重定向,因此必须使用外部上下文#重定向()
可以在完成
时使用,但这将不必要地涉及到服务器的两次往返,首先将货币值设置为关联的托管bean,然后进行重定向
在给出的示例中,如何使用
includeViewParams=true
进行重定向?与faces redirect=true
,includeViewParams=true
仅在导航结果中有效,而不在传递到ExternalContext\redirect()
的“普通”URL中有效
使用
或者,用
一个可疑的替代方法是自己收集所有视图参数并将其转换为查询字符串,这样您就可以使用ExternalContext\redirect()
。使用OmniFaces更容易做到这一点
Faces.redirect(viewId + "?" + Servlets.toQueryString(Faces.getViewParameterMap()));
我记不起我在哪里读过,但我在某个地方读到,
NavigationHandler#handleNavigation()
是JSF 1.x的一个老习惯。它是?因此,我没有想到使用它。在faces config.xml
中的
things中的显式导航案例是一种古老的做法。
<p:selectOneMenu value="#{currencyRateBean.currencyHolder}">
<f:selectItems var="row" value="#{currencyBean.currencies}"
itemLabel="#{row.currency}"
itemValue="#{row}"/>
<p:ajax event="change"
listener="#{currency.currencyAction}"
partialSubmit="true"
process="@this"
update="@none"/>
</p:selectOneMenu>
public void currencyAction() throws IOException {
// ...
FacesContext facesContext = FacesContext.getCurrentInstance();
String viewId = facesContext.getViewRoot().getViewId();
ExternalContext externalContext = facesContext.getExternalContext();
externalContext.redirect(externalContext.getRequestContextPath() + viewId + "?includeViewParams=true");
}
FacesContext context = FacesContext.getCurrentInstance();
String outcome = viewId + "?includeViewParams=true";
context.getApplication().getNavigationHandler().handleNavigation(context, null, outcome);
Faces.navigate(viewId + "?includeViewParams=true");
Faces.redirect(viewId + "?" + Servlets.toQueryString(Faces.getViewParameterMap()));