ui:repeat中的f:ajax,组件的未知ID [英] f:ajax within ui:repeat, unknown id for the component

查看:186
本文介绍了ui:repeat中的f:ajax,组件的未知ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试通过ajax调用呈现panelGroup时,它会给出未知的ID.

When I try to render a panelGroup by an ajax call, it gives unknown id.

<h:form id="form1" prependId=false>
  <h:panelGroup id="panel1">
       <h:dataTable/>
       <ui:repeat value="#{bean.page}" var="page">
          <h:commandLink value="#{page}">
              <f:ajax execute="@form" render="panel1" listener="#{bean.page}" />
          </h:commandLink>
       </ui:repeat>
  </h:panelGroup>     
 </h:form>

当我尝试这段代码时,它给出了未知的id panel1.我也尝试使用id:panel1".我遇到同样的错误.

When I tried this code, it gives unknown id panel1. I tried with id ":panel1" too. I get the same error.

推荐答案

相对客户端ID(即不以:开头)相对于当前父客户端<ui:repeat>的上下文中寻找组件.这行不通.绝对客户端ID(即以:开头)正在视图根上下文中寻找组件.但是,您将它放在<h:form>-反过来又是另一个NamingContainer组件-内,因此render=":panel"也不起作用.

A relative client ID (i.e. not starting with :) is relative to the current parent NamingContainer component. The <ui:repeat> is also a NamingContainer. So the render="panel1" is looking for the component within the context of <ui:repeat>. This isn't going to work. An absolute client ID (i.e. starting with :) is looking for the component within the context of view root. But you've it inside a <h:form> -which is in turn another NamingContainer component-, so the render=":panel" is also not going to work.

以下内容应该起作用,并删除prependId="false"以便您可以引用它:

The following should work, with prependId="false" removed so that you can refer it:

<h:form id="form1">
  <h:panelGroup id="panel1">
    <h:dataTable/>

    <ui:repeat value="#{bean.page}" var="page">
      <h:commandLink value="#{page}">
        <f:ajax execute="@form" render=":form1:panel1" listener="#{bean.page}" />
      </h:commandLink>
    </ui:repeat>
  </h:panelGroup> 
</h:form>

顺便说一句,如果您实际上只想呈现表格,那么您应该这样做:

By the way, if you actually want to render only the table, then you should be doing this:

<h:form id="form1">
  <h:panelGroup>
    <h:dataTable id="table1" />

    <ui:repeat value="#{bean.page}" var="page">
      <h:commandLink value="#{page}">
        <f:ajax execute="@form" render=":form1:table1" listener="#{bean.page}" />
      </h:commandLink>
    </ui:repeat>
  </h:panelGroup> 
</h:form>


更新:根据注释,事实证明您已通过配置将JSF默认的NamingContainer分隔符从:更改为_.在这种情况下,您需要在客户端ID选择器中使用_而不是:.


Update: as per the comments, it turns out that you have changed the JSF default NamingContainer separator character from : to _ by configuration. In that case, you need to use _ instead of : in the client ID selector.

<f:ajax execute="@form" render="_form1_panel1" listener="#{bean.page}" />

这篇关于ui:repeat中的f:ajax,组件的未知ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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