在 ui:repeat Myfaces 2.2.9 + primefaces 5.3 上无法正常生成 ID

Does not work properly id generation on ui:repeat My faces 2.2.9 + prime faces 5.3

实际上我正在使用 Myfaces 版本 2.2.9 并且我有以下结构来根据用户选择的特定编号生成任何面板。

...
<ui:repeat value="#{garajes}" var="garaje" varStatus="loop">
<p:panelGrid >
    <h:outputLabel value="Numero de garaje #{loop.index+1}: " />
    <h:outputLabel value="Matricula  #{loop.index+1}: " />

    <p:inputText   value="#{garaje.numeroGaraje}"   maxlength="5" >
    </p:inputText>

    <p:inputText id="matriculaInmobiliariaGaraje-#{loop.index+1}"   value="#{garaje.matriculaInmobiliaria}" 
        maxlength="20">
    </p:inputText>

    ...

</p:panelGrid>
</ui:repeat>
....

所以,当呈现上面的代码时,标识符很奇怪,还有像下图这样的东西:

所以我不知道如何删除 id 中的这些奇怪的东西

注意:我需要一个特定的 ID 来更新循环内的另一个组件。

如何在 ui:repeat 中获得正确的标识符?

具体问题,给所有NamingContainer个组件一个固定的ID即可。这包括 <ui:repeat> 本身。

<ui:repeat id="garajes" ...>

至于具体要求,你把事情复杂化了。 NamingContainer 本身会担心 children 的 ID 的唯一性。您在 id="matriculaInmobiliariaGaraje-#{loop.index+1}" 中的尝试根本行不通,因为 #{loop} 变量在视图构建期间不可用,当使用 id 实例化组件时。摆脱它。您可以在 NamingContainer 中仅使用相对 ID 来引用同一 NamingContainer.

中的另一个组件
<ui:repeat ...>
    <p:inputText id="foo" />
    <p:inputText ...><p:ajax ... update="foo" /></p:inputText>
</ui:repeat>

这会很好用。

另请参阅:

  • How to find out client ID of component for ajax update/render? Cannot find component with expression "foo" referenced from "bar"
  • How to use EL with <ui:repeat var> in id attribute of a JSF component