在将页面加载到JSF2中之前进行重定向 [英] Redirect before loading the page in JSF2
本文介绍了在将页面加载到JSF2中之前进行重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个要求,在页面即将加载之前,我想检查查询字符串是否存在,如果查询字符串存在,那么我想重定向到另一个页面而不是当前页面,我该如何处理这种类型的要求JSF 2.
I have a requirement that before the page is going to load i want to check whether query string exists or not if query string exists then i want to redirect to another page instead of current page how can i handle this type of requirement in JSF 2.
预先感谢
推荐答案
在JSF 2.2上,您可以为此使用<f:viewAction>
.
When on JSF 2.2, you can use <f:viewAction>
for this.
<f:metadata>
<f:viewParam name="paramName" value="#{bean.paramName}" />
<f:viewAction action="#{bean.check}" />
</f:metadata>
(paramName
是您的查询字符串参数的名称)
(paramName
is the name of your query string parameter)
private String paramName; // +getter+setter
public String check() {
if (paramName == null) {
return "error.xhtml";
}
return null;
}
当尚未使用JSF 2.2(JSF 2.0/2.1)时,您可以为此使用<f:event type="preRenderView">
.
When not on JSF 2.2 yet (JSF 2.0/2.1), you can use <f:event type="preRenderView">
for this.
<f:metadata>
<f:viewParam name="paramName" value="#{bean.paramName}" />
<f:event type="preRenderView" listener="#{bean.check}" />
</f:metadata>
private String paramName; // +getter+setter
public void check() throws IOException {
if (paramName == null) {
FacesContext.getCurrentInstance().getExternalContext().redirect("error.xhtml");
}
}
另请参见:
- 可以做什么< f:metadata> ;,< f:viewParam>和< f:viewAction>用于吗?
- What can <f:metadata>, <f:viewParam> and <f:viewAction> be used for?
See also:
这篇关于在将页面加载到JSF2中之前进行重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文