加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 03:12:05 所属栏目:百科 来源:网络整理
导读:我试图ajax更新一个有条件渲染的组件。 h:form ... h:commandButton value="Login" action="#{login.submit}" f:ajax execute="@form" render=":text" / /h:commandButton/h:formh:outputText id="text" value="You're logged in!" rendered="#{not empty us
我试图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”

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读