这个问题与这个(已经回答)密切相关.
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 将返回一个字符串,例如selected-flight-review 将引导用户到 selected-flight-review.xhtml
selectFlight would return a string, e.g. selected-flight-review which would direct the user to selected-flight-review.xhtml
出于移动目的,我必须使用 ajax 调用使 panelGrid 可点击,例如
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 以外的其他东西(我宁愿不这样做),还是有什么方法可以使这项工作像现在这样?
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(); }更多推荐
从 ajax 侦听器方法内部发送重定向
发布评论