jsf – Ajax update/render在已渲染属性的组件上不起作用

我试图ajax更新一个有条件渲染的组件。
<h:form>
    ...
    <h:commandButton value="Login" action="#{login.submit}">
        <f:ajax execute="@form" render=":text" />
    </h:commandButton>
</h:form>
<h:outputText id="text" value="You're logged in!" rendered="#{not empty user}" />

但是,这不行。我可以确保#{user}实际上是可用的。这是怎么引起的,我该如何解决呢?

如果组件本身没有呈现在第一位,则不可能通过ajax重新渲染(更新)组件。必须始终在ajax可以重新呈现之前呈现组件。 Ajax正在使用JavaScript document.getElementById()来查找需要更新的组件。但是如果JSF没有将组件放在第一位,那么JavaScript找不到要更新的内容。

解决方案是简单地引用总是渲染的父组件。

<h:form>
    ...
    <h:commandButton ...>
        <f:ajax ... render=":text" />
    </h:commandButton>
</h:form>
<h:panelGroup id="text">
    <h:outputText ... rendered="#{not empty user}" />
</h:panelGroup>

也可以看看:

> Why do I need to nest a component with rendered=”#{some}” in another component when I want to ajax-update it?
> How to find out client ID of component for ajax update/render? Cannot find component with expression “foo” referenced from “bar”

相关文章

$.AJAX()方法中的PROCESSDATA参数 在使用jQuery的$.ajax()方...
form表单提交的几种方式 表单提交方式一:直接利用form表单提...
文章浏览阅读1.3k次。AJAX的无刷新机制使得在注册系统中对于...
文章浏览阅读1.2k次。 本文将解释如何使用AJAX和JSON分析器在...
文章浏览阅读2.2k次。/************************** 创建XML...
文章浏览阅读3.7k次。在ajax应用中,通常一个页面要同时发送...