【问题标题】:<f:ajax> contains an unknown id :someid when used in <ui:repeat><f:ajax> 在 <ui:repeat> 中使用时包含未知 id :someid
【发布时间】:2011-08-31 14:16:21
【问题描述】:

我的代码sn-p:

<ui:repeat var="o">
   <h:panelGroup id="someid">
      <ui:repeat>
         // HTML
      </ui:repeat>
   </h:panelGroup>

   <div>
      <h:form>
          <h:commandButton action="#{o.doSomething}">
              <f:ajax event="action" render=":someid" />
          </h:commandButton>
      <h:form>
   </div>
</ui:repeat>

为什么&lt;f:ajax&gt; 没有找到someid

【问题讨论】:

    标签: jsf-2


    【解决方案1】:

    这是不可能的。 &lt;ui:repeat&gt; 在客户端 ID 前面加上自己的 ID 和索引。所有这些面板组的 ID 为 j_id1:0:someidj_id1:1:someidj_id1:2:someid 等。以下内容应该适用于您的特定构造:

    <f:ajax render=":#{component.parent.parent.clientId}:someid" />
    

    这将动态添加&lt;ui:repeat&gt; 的当前客户端ID。但是,它仅在您使用 MyFaces 而不是 Mojarra 时才有效。 &lt;ui:repeat&gt; 在 Mojarra 中以多种方式损坏。他们已经为 2.2 安排了许多修复。

    另一种方法是将它们分组到一个常见的NamingContainer 组件中,例如&lt;h:form&gt;,以便您可以使用相对 ID。

    <ui:repeat var="o">
        <h:form>
            <h:panelGroup id="someid">
                <ui:repeat>
                    // HTML
                </ui:repeat>
            </h:panelGroup>
    
            <div>
                <h:commandButton action="#{o.doSomething}">
                    <f:ajax event="action" render="someid" />
                </h:commandButton>
            </div>
        <h:form>
    </ui:repeat>
    

    【讨论】:

    • 谢谢。但我想渲染整个外部 ui:repeat 。那么,我该怎么做呢?
    • 哦?你在问题中没有说清楚。只需将外部&lt;ui:repeat&gt; 放入&lt;h:panelGroup id="foo"&gt; 并使用render=":foo"(或无论其实际 客户端ID 是什么,在浏览器中右键单击页面并执行View Source 即可找到它)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-06
    • 2011-10-14
    • 1970-01-01
    • 2012-01-02
    • 1970-01-01
    • 2012-04-09
    • 2011-04-02
    相关资源
    最近更新 更多