从 ajax 侦听器方法内部发送重定向

编程入门 行业动态 更新时间:2024-10-11 01:13:48
本文介绍了从 ajax 侦听器方法内部发送重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这个问题与这个(已经回答)密切相关.

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 侦听器方法内部发送重定向

本文发布于:2023-11-24 19:40:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1626552.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:侦听器   重定向   方法   ajax

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!