当发送的请求是 Ajax 请求时,如何从 ManagedBean 重定向? [英] How to redirect from a ManagedBean for when the request sent is an Ajax request?

查看:25
本文介绍了当发送的请求是 Ajax 请求时,如何从 ManagedBean 重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 JSF2 中使用 PrimeFaces.我试图通过将登录名和密码作为 Ajax 请求发送来验证用户.在支持 bean 的操作方法中,我尝试验证用户并在验证成功时重定向到新视图.

I am using PrimeFaces with JSF2. I am trying to authenticate user by sending login and password as an Ajax request. And in the action method of the backing bean, I am trying to validate user and redirect to a new view if the validation succeeds.

这在使用 primefaces 时可能吗?

Is this possible while using primefaces?

因为我认为使用 primefaces 的 p:commandButton,我只能有 ajax 行为或导航.

Because I think with primefaces' p:commandButton, I can only either have ajax behavior or the navigation.

推荐答案

是的,只需发送重定向而不是(默认)转发作为结果.<navigation-case>-less JSF 2.0 方法是将 ?faces-redirect=true 附加到 action 方法中的结果字符串.

Yes, just send a redirect instead of a (default) forward as outcome. The <navigation-case>-less JSF 2.0 way would be appending ?faces-redirect=true to the outcome string in the action method.

例如

public String login() {
    // ...
    return "home?faces-redirect=true";
}

这篇关于当发送的请求是 Ajax 请求时,如何从 ManagedBean 重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆