问题描述
我有服务器端计算计数器.当它== 0时,方法应执行ExternalContext#dispatch()
,但没有执行.方法ExternalContext#redirect()
在此位置正确工作.
I have server-side coundown counter. When it == 0, method should execute ExternalContext#dispatch()
, but it didn't do it. Method ExternalContext#redirect()
works correctly on this place.
....
}else{
try {
FacesContext.getCurrentInstance().getExternalContext().dispatch("result.xhtml");
} catch (IOException e) {
e.printStackTrace();
}
}
....
我尝试了几种拼写url(result,result.xhtml,\result.xhtml
等)的方法,结果相同.
I tried a few ways of the spelling url(result,result.xhtml,\result.xhtml
etc.) with the same result.
推荐答案
这不是让JSF导航到其他视图的正确方法.
This is not the right way to let JSF navigate to a different view.
如果您在操作方法中,则应将其作为字符串返回.
If you're inside an action method, you should be returning it as string instead.
public String submit() {
// ...
return "result.xhtml";
}
或者,如果您不属于某个操作方法,并且由于某些不清楚的原因而无法将其更改为完全有价值的操作方法,请使用 NavigationHandler#handleNavigation()
.
Or if you're not inside an action method and couldn't change it to a fullworthy action method for some unclear reason, then use NavigationHandler#handleNavigation()
instead.
FacesContext context = FacesContext.getCurrentInstance();
context.getApplication().getNavigationHandler().handleNavigation(context, null, "result.xhtml");
这篇关于ExternalContext#dispatch()不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!