JSF 2:网页Ajax调用后重定向 [英] JSF 2: page redirect after ajax call

查看:154
本文介绍了JSF 2:网页Ajax调用后重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被困在类似一个导航案例问题。 在几句话,我想重新定向导航从一个网页到另一个,使用呈现一个Ajax H:commandLink 。 下面是支持bean

I'm stuck in a navigation case problem similar to this one. In a few words, I'm trying to redirect navigation from one page to another, using an ajax rendered h:commandLink. Here's the backing bean

@ManagedBean
public class StartBean {

    public void search(){
        FacesContext
            .getCurrentInstance()
            .getExternalContext()
            .getFlash()
            .put("result", "hooray!")
        ;
    }

    public String showResult(){
        return "result?faces-redirect=true";
    }
}

和起始页

<h:body>
    <h:form prependId="false">
        <h:commandButton value="Click" action="#{startBean.search}">
            <f:ajax execute="@this" render="@form"/>
        </h:commandButton>

        <br/>

        <h:commandLink 
            action="#{startBean.showResult()}" 
            rendered="#{flash.result != null}" 
            value="#{flash.result}"
        />

    </h:form>
</h:body>

,而结果页面只是显示一条消息。这两个网页上的Web模块上下文根。 它发生在 H:commandLink 显示正常后,阿贾克斯提交,但点击它会导致页面刷新。它不会对的结果重定向页,符合市场预期。 它之后,表示如果加载页面(F5),结果页。这似乎是一个渲染周期事

whereas result page is just showing a message. Both pages are on web module context root. It happens that the h:commandLink is correctly displayed after ajax submit, but clicking on it causes a page refresh. It doesn't redirect towards the result page, as expected. After it, if page is reloaded (F5), result page is shown. It seems to be a rendering cycle matter.

任何建议?

在此先感谢。

推荐答案

渲染的所有输入和命令组件属性的重新评估当表单提交。所以,如果它评估,那么JSF根本不会调用动作。当搜索请求/响应()方法完成闪光范围被终止。这是不存在的闪存范围了,当你发送 showResult()的请求。我建议把豆在视图范围并绑定渲染属性,它的属性。

The rendered attribute of all input and command components is re-evaluated when the form is submitted. So if it evaluates false, then JSF simply won't invoke the action. The Flash scope is terminated when the request/response of the search() method is finished. It isn't there in the Flash scope anymore when you send the request of the showResult(). I suggest to put the bean in the view scope and bind the rendered attribute to its property instead.

@ManagedBean
@ViewScoped
public class StartBean {

    private String result;

    public void search(){
        result = "hooray";
    }

    public String showResult(){
        return "result?faces-redirect=true";
    }

    public String getResult() {
        return result;
    }

}

<h:commandLink 
    action="#{startBean.showResult}" 
    rendered="#{startBean.result != null}" 
    value="#{startBean.result}"
/>

参见:

  • <一个href="http://stackoverflow.com/questions/2118656/hcommandlink-hcommandbutton-is-not-being-invoked">h:commandLink / H:的commandButton没有被调用
  • See also:

    • h:commandLink / h:commandButton is not being invoked
    • 这篇关于JSF 2:网页Ajax调用后重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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