Empty values of <h:selectOneMenu>inside <ui:repeat> is not set to backing bean during ajax call

3k Views Asked by At

The empty/null value of the h:selectOneMenu during the ajax call is not set to the property in the backing bean, whereas if I select any dropdown item which has non empty / not null value, it is set to the property in the backing bean during the ajax call. I have notice this behaviour only if I use h:selectOneMenu & f:ajax inside the ui:repeat tag. And, without the ui:repeat tag , the values(both empty and non empty) are set properly to the property in the backing bean during the ajax call.

Below is the code snipet of the above mentioned scenario:

<h:panelGrid id="details">
<ui:repeat id="listId" value="#{new.List}" var="item" varStatus="itemStatus">
    <h:panelGrid id="idDoc">
    <ui:repeat id="docListId" value="#{item.docs}" var="docItem" varStatus="docStatus">
        <h:selectOneMenu id="type"  value="#{docItem.docType}" label="Type" style="" styleClass='' >

                <f:selectItems value="#{new.docSelections}"/>

                <f:ajax onevent="refreshDoc" event="valueChange" render="@this :form:listId:docListId:idDoc" execute=":form:listId:details" listener="#{new.save}"/>
            </h:selectOneMenu>
    </ui:repeat>
    </h:panelGrid>
</ui:repeat>
</h:panelGrid>

Is there any problem in the way that I have used the ui:repeat,h:selectoneMenu and f:ajax?

1

There are 1 best solutions below

1
On

You seem to be using Mojarra. It has indeed had several issues related to (nested) <ui:repeat> and component state saving. Try upgrading Mojarra to the latest version.

An alternative is to just replace <h:panelGrid><ui:repeat> by a <h:dataTable> as it effectively generates the same markup. The <h:dataTable> doesn't suffer from the <ui:repeat> issues.

<h:dataTable id="details" value="#{new.List}" var="item" binding="#{itemStatus}">
  <h:column>
    <h:dataTable id="idDoc" value="#{item.docs}" var="docItem" binding="#{docStatus}">
      <h:column>
        <h:selectOneMenu id="type"  value="#{docItem.docType}" label="Type" style="" styleClass='' >
          <f:selectItems value="#{new.docSelections}"/>
          <f:ajax onevent="refreshDoc" event="valueChange" render="@this :form:listId:docListId:idDoc" execute=":form:listId:details" listener="#{new.save}"/>
        </h:selectOneMenu>
      </h:column>
    </h:dataTable>
  </h:column>
</h:dataTable>