【问题标题】:AJAX not working with myfaces 2.1 and rich faces 4.3AJAX 不适用于 myfaces 2.1 和rich faces 4.3
【发布时间】:2014-01-03 17:32:08
【问题描述】:

我们正在从 jsf 1.2 升级到 jsf 2。 我们使用的是 apache myfaces 2.1 和 rich faces 4.3。

问题是,<a4j:commandButton> 标记 AJAX 功能似乎已损坏。 下面是xhtml文件。

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:a4j="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich">


    <h:form prependId="false" id="questionsForm">   

        <!-- other form fields are not shown -->
        <a4j:commandButton  id="questions" value="Clear" action="#{bean.clearAction}"/> 
    </h:form>

</html> 

单击“清除”按钮时,后端代码会执行,但会重新加载整个页面(页面再次刷新)。 预迁移代码可以完美运行,无需重新加载页面。

任何人都可以帮助如何让这个 AJAX 在富面孔标签中工作吗?

【问题讨论】:

    标签: jsf-2 richfaces myfaces


    【解决方案1】:

    作为给定的属性你必须告诉a4j:commandButton

    • 您希望执行哪些部分(例如应更新当前页面的哪些输入字段)
    • 您希望重新呈现页面的哪些部分

    第一个是使用属性execute 完成的,最后一个是使用属性render 完成的。如果两者都没有给出,则按钮的行为类似于传统的h:commandButton(解释了所描述的行为)

    更新:还要检查&lt;head&gt;&lt;body&gt; 标记必须像&lt;h:head&gt;&lt;h:body&gt; 这样JSF 有机会添加强制性的javascript 和css 库。

    更新:您是否仔细检查过您的操作返回 void/""/null 而不是任何转发? (另见"a4j:commandButton makes a full page reload RichFaces 3.3.3 CR1"

    【讨论】:

    • @lray:感谢您的回复。我尝试提供执行和渲染属性值,但行为没有改变。页面重新加载仍然发生。
    • @lray:我也试过添加 h:head 和 h:body ,但同样的问题存在
    • @Atul 刚刚在本地进行了测试,但使用的是 Mojarra Faces 2.1.7 和 Richfaces 4.3.3 Final。即使没有渲染/执行,也不会发生新的重新加载。所以它必须是给定 xhtml - 代码之外的问题。
    • @lray:谢谢,是的,我之前检查过我的方法返回 void ,也尝试从中返回 null ,但没有成功。我同意它必须是外部 xhtml 问题。找到解决方法后会发布原因
    • 好的。好吧,祝你好运......是的,我们将不胜感激。 :-)
    猜你喜欢
    • 1970-01-01
    • 2011-08-25
    • 1970-01-01
    • 2013-04-11
    • 1970-01-01
    • 2013-05-19
    • 2020-05-10
    • 2011-10-01
    • 1970-01-01
    相关资源
    最近更新 更多