Checkbox ValueChangeListener problem in af:table – ADF 12.1.3

Sharing is Caring

Recently I faced a problem while working on one of my application, it has an editable table having one checkbox column and a valueChangeListener is defined on that checkbox.

Problem is that whenever the user selects any row of the table, valueChangeListener of checkbox is called every time for all editable rows, this is weird because VCL should execute only when the user selects or deselects a checkbox
Here I am showing the same problem, I have used Department table of HR Schema to create business components and dropped Department viewObject as a table on the page, added a transient attribute to use as checkbox

See af:table XML source on the page-

<af:table value="#{bindings.Departments1.collectionModel}" var="row"
                          rows="#{bindings.Departments1.rangeSize}"
                          emptyText="#{bindings.Departments1.viewable ? 'No data to display.' : 'Access Denied.'}"
                          rowBandingInterval="0" selectedRowKeys="#{bindings.Departments1.collectionModel.selectedRow}"
                          selectionListener="#{bindings.Departments1.collectionModel.makeCurrent}" rowSelection="single"
                          fetchSize="#{bindings.Departments1.rangeSize}"
                          filterModel="#{bindings.Departments1Query.queryDescriptor}"
                          queryListener="#{bindings.Departments1Query.processQuery}" filterVisible="true" varStatus="vs"
                          id="t1">
                    <af:column sortProperty="#{bindings.Departments1.hints.DepartmentId.name}" filterable="true"
                               sortable="true" headerText="#{bindings.Departments1.hints.DepartmentId.label}" id="c1">
                        <af:outputText value="#{row.DepartmentId}"
                                       shortDesc="#{bindings.Departments1.hints.DepartmentId.tooltip}" id="ot1">
                            <af:convertNumber groupingUsed="false"
                                              pattern="#{bindings.Departments1.hints.DepartmentId.format}"/>
                        </af:outputText>
                    </af:column>
                    <af:column sortProperty="#{bindings.Departments1.hints.DepartmentName.name}" filterable="true"
                               sortable="true" headerText="#{bindings.Departments1.hints.DepartmentName.label}" id="c2">
                        <af:outputText value="#{row.DepartmentName}"
                                       shortDesc="#{bindings.Departments1.hints.DepartmentName.tooltip}" id="ot2"/>
                    </af:column>
                    <af:column sortProperty="#{bindings.Departments1.hints.ManagerId.name}" filterable="true"
                               sortable="true" headerText="#{bindings.Departments1.hints.ManagerId.label}" id="c3">
                        <af:outputText value="#{row.ManagerId}"
                                       shortDesc="#{bindings.Departments1.hints.ManagerId.tooltip}" id="ot3">
                            <af:convertNumber groupingUsed="false"
                                              pattern="#{bindings.Departments1.hints.ManagerId.format}"/>
                        </af:outputText>
                    </af:column>
                    <af:column sortProperty="#{bindings.Departments1.hints.LocationId.name}" filterable="true"
                               sortable="true" headerText="#{bindings.Departments1.hints.LocationId.label}" id="c4">
                        <af:outputText value="#{row.LocationId}"
                                       shortDesc="#{bindings.Departments1.hints.LocationId.tooltip}" id="ot4">
                            <af:convertNumber groupingUsed="false"
                                              pattern="#{bindings.Departments1.hints.LocationId.format}"/>
                        </af:outputText>
                    </af:column>
                    <af:column headerText="#{bindings.Departments1.hints.selectCheckBxTrans.label}" id="c5">
                        <af:selectBooleanCheckbox value="#{row.bindings.selectCheckBxTrans.inputValue}"
                                                  label="#{row.bindings.selectCheckBxTrans.label}"
                                                  shortDesc="#{bindings.Departments1.hints.selectCheckBxTrans.tooltip}"
                                                  id="sbc1" autoSubmit="true"
                                                  valueChangeListener="#{pageFlowScope.CheckBoxBean.checkBoxVCE}"/>
                    </af:column>
                </af:table>

and it’s pageDef file looks like this –

 <bindings>
    <tree IterBinding="Departments1Iterator" id="Departments1">
      <nodeDefinition DefName="checkbox.model.view.DepartmentsVO" Name="Departments10">
        <AttrNames>
          <Item Value="DepartmentId"/>
          <Item Value="DepartmentName"/>
          <Item Value="ManagerId"/>
          <Item Value="LocationId"/>
          <Item Value="selectCheckBxTrans"/>
        </AttrNames>
      </nodeDefinition>
    </tree>
    <button IterBinding="Departments1Iterator" id="selectCheckBxTrans" DTSupportsMRU="false" StaticList="true">
      <AttrNames>
        <Item Value="selectCheckBxTrans"/>
      </AttrNames>
      <ValueList>
        <Item Value="Y"/>
        <Item Value="N"/>
      </ValueList>
    </button>
  </bindings>

So this is the whole case that creates this problem, I have tried setting changeEventPolicy of the iterator to none but no luck
Actual problem was that attribute binding for selectCheckBxTrans is present but doesn’t bind  table checkbox so just changed the pageDef code and added this reference in checkbox item value

 <Item Value="selectCheckBxTrans" Binds="selectCheckBxTrans"/>

and everything is working properly now 🙂
By default when we drop attribute as checkbox Binds property is there in pageDef still if anyone faces this type of behaviour then double check pageDef file

Sample ADF Application that reproduces this problem – Download
Cheers:) Happy Learning

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *