这个问题是密切相关的这一(已回答)。
This question is closely related to this one (which has been answered).
在我的项目,我浏览使用JSF命令按钮,其中的action属性会指向一个函数,该函数返回一个字符串屏幕之间。该字符串是新屏幕的名称例如。
Throughout my project, I navigate between screens using JSF command buttons, where the action attribute would point to a function that returns a string. The string is the new screen's name e.g.
<h:commandButton value="Select" action="#{searchResultsBundledBean.selectFlight}">
</h:commandButton>
selectFlight
会返回一个字符串,如: 选择飞行审查
这会引导用户到选择-飞行review.xhtml
selectFlight
would return a string, e.g. selected-flight-review
which would direct the user to selected-flight-review.xhtml
有关移动目的,我不得不做出一个 panelGrid中
点击使用Ajax调用,如:
For mobile purposes I had to make a panelGrid
clickable using an ajax call, e.g.
<h:panelGrid>
<f:ajax event="click" listener="#{searchResultsBundledBean.clickFlight(lowFareBundledSearchItem)}"/>
</h:panelGrid
这工作,我测试过它,并且返回正确的结果(测试与记录它的权利之前,它的返回)
This works, I've tested it, and the correct result is returned(Tested with logging it right before it's returned)
然而,没有重定向发生。 Ajax调用不这样做呢。我如何使它重定向到另一个屏幕?我没有送过任何变量,我只需要新的屏幕显示。我应该用其他的东西比AJAX(我想preFER不要),或者是有一些方法,使这项工作现在是这样?
However, no redirection takes place. The ajax call doesn't do it yet. How do I make it redirect to another screen? I don't have to send through any variables, I just need the new screen to be displayed. Should I use something other than ajax(I would prefer not to), or is there some way to make this work the way it is now?
您可以重定向从支持bean的响应:
You can redirect the response from the backing bean:
public void clickFlight(Item lowFareBundledSearchItem) throws IOException {
// ...
FacesContext.getCurrentInstance().getExternalContext().redirect("selected-flight-review.xhtml");
FacesContext.getCurrentInstance().responseComplete();
}