Follow by Email

Tuesday, 15 December 2015

Checkbox ValueChangeListener problem in af:table - ADF 12.1.3


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

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

 See af:table XML source on 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 iterator to none but no luck
Actual problem was that attribute binding for selectCheckBxTrans is present but doesn't bind  table check box so just changed pageDef code and added this reference in check box 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 face this type of behavior then double check pageDef file

Sample ADF Application that reproduce this problem - Download
Cheers:) Happy Learning

No comments :

Post a Comment