JSF(Primefaces) 通过 ID 更新多个元素的 ajax [英] JSF(Primefaces) ajax update of several elements by ID's

查看:19
本文介绍了JSF(Primefaces) 通过 ID 更新多个元素的 ajax的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

还有一个关于 JSF 的问题.特别是 Primefaces.
同时通过 id 更新元素的 ajax 存在以下问题.如果页面上的元素一个接一个,则 ajax 更新执行正常:

One more question concerning JSF.Particularly, Primefaces.
Have following problem with ajax update of elements by id's at same time. If elements on page goes one by one ,that ajax update performs ok:

<ui:repeat value="#{showProducts.inCart}" var="cart">
 <td><p:spinner min="0" value="#{cart.count}" immediate="true">
 <p:ajax process="@this" update="count,subTotal"/></p:spinner></td>         
 <td><h:outputText value="#{cart.totalPrice}" id="count"/></td>
 <h:outputText value="#{showProducts.subTotal}" id="subTotal"/>      
</ui:repeat>

这里id为count"的元素排在第一位,然后id为subtotal"的元素排在第二位.如果页面上的元素不是严格一个一个的,则不会更新具有小计"id 的第二个元素:

Here element with id "count" goes first,then element with id "subtotal" goes second. In case,elements on page are not strictly one by one,that second element with "subtotal" id is not updated:

    <ui:repeat value="#{showProducts.inCart}" var="cart">
      <td><p:spinner min="0" value="#{cart.count}" immediate="true">
<p:ajax process="@this" update="count,subTotal"/></p:spinner></td>         
      <td><h:outputText value="#{cart.totalPrice}" id="count"/></td>
      <td><h:outputText value="#{cart.place}" /></td>
    </ui:repeat>
    <h:outputText value="#{showProducts.subTotal}" id="subTotal"/> 

这是正常行为还是我遗漏了一些参数?

Is it normal behaviour or I miss some parameters?

推荐答案

如果要更新的组件不在同一个NamingContainer 组件 (ui:repeat, h:formh:dataTable 等),则需要指定绝对"客户端 ID.以 : 为前缀(默认的 NamingContainer 分隔符)从根开始.

If the to-be-updated component is not inside the same NamingContainer component (ui:repeat, h:form, h:dataTable, etc), then you need to specify the "absolute" client ID. Prefix with : (the default NamingContainer separator character) to start from root.

<p:ajax process="@this" update="count :subTotal"/>

为了确定实际值,请检查生成的 HTML 中 subTotal 组件的客户端 ID.如果它也在例如 h:form 中,那么它也带有它的客户端 ID 前缀,您需要相应地修复它.

To be sure, check the client ID of the subTotal component in the generated HTML for the actual value. If it's inside for example a h:form as well, then it's prefixed with its client ID as well and you would need to fix it accordingly.

<p:ajax process="@this" update="count :formId:subTotal"/>

更推荐使用空格分隔 ID,因为 不支持逗号分隔,否则初学者会感到困惑.

Space separation of IDs is more recommended as <f:ajax> doesn't support comma separation and starters would otherwise get confused.

这篇关于JSF(Primefaces) 通过 ID 更新多个元素的 ajax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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