Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

f:ajax within ui:repeat, unknown id for the component [duplicate]

Tags:

jsf-2

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>

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

like image 781
user679526 Avatar asked Aug 17 '11 05:08

user679526


1 Answers

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.

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>

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}" />
like image 186
BalusC Avatar answered Sep 30 '22 12:09

BalusC