Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

ADF table row selection returns first row for every selection event

953564Aug 13 2012 — edited Oct 8 2013
Hello all,

I'm new to ADF and I'm trying to learn how selection event handling works. The problem I am facing is I would like the enable/disable a button(ctb1) based on a selection events from partialTriggers on my table(t1). To do this I created a table (t1) and my button listens for trigger events to update its state(enable/disabled). The issue I am seeing is when I attempt to grab a hold of the current row selection it seems to be returning data from the first row every time (for example, I click on the third row in my table, and instead of getting data from the third row I get data from the first row, click on second row same thing)

Below is the code for my table and button:

When My page renders it seems it gets the first row of my table and when I select another row its grabbing the first row data every time. I also notice that when I select the first row in this table no selection event is fired (i.e the partialTrigger on ctb1 is never fired).
<af:commandToolbarButton text="#{resourceuiBundle.EnableDisabledBtn}"
                                               id="ctb1"
                                               disabled="#{!viewScope.ManagedModelBean.testEnabled}"
                                               partialSubmit="true"
                                               icon="/images/awesomeImage.png"
                                               actionListener="#{ManagedBean.doSomething}"
                                               partialTriggers="t1"/>

<af:table value="#{bindings.EmployeeROVO.collectionModel}"
                            var="row"
                            rows="#{bindings.EmployeeROVO.rangeSize}"
                            summary="#{resourceuiBundle.SOMEAWESOMESUMMARY}"
                            emptyText="#{bindings.EmployeeROVO.viewable ? resourceuiBundle.NO_DATA_TO_DISPLAY : resourceuiBundle.ACCESS_DENIED}"
                            fetchSize="#{bindings.EmployeeROVO.rangeSize}"
                            rowBandingInterval="1"
                            selectedRowKeys="#{bindings.EmployeeROVO.collectionModel.selectedRow}"
                            selectionListener="#{bindings.EmployeeROVO.collectionModel.makeCurrent}"
                            rowSelection="single" id="t1"
                            columnStretching="last"
                            binding="#{ManagedBean.targetTable}"
                            visible="#{ManagedBean.tableVisible}">
                    <af:column sortProperty="TargetName" sortable="true"
                               headerText="#{bindings.EmployeeROVO.hints.TargetName.label}"
                               id="c1" rowHeader="unstyled" width="300">
                      <af:panelGroupLayout id="pgl5">
                        <af:image id="i2"
                                  source="#{ImageMap.targetType16[row.TargetType]}"
                                  shortDesc=""/>
                        <af:spacer width="2" height="10" id="s4"/>
                        <af:outputText value="#{row.TargetName}" id="ot9"/>
                      </af:panelGroupLayout>
                    </af:column>
                    <af:column sortProperty="TargetStatus" sortable="true"
                               headerText="#{bindings.EmployeeROVO.hints.TargetStatus.label}"
                               id="c4">
                      <af:outputText value="#{row.TargetStatus}" id="ot8"/>
                    </af:column>
                    <af:column sortProperty="SetNameLabel" sortable="true"
                               headerText="#{bindings.EmployeeROVO.hints.SetNameLabel.label}"
                               id="c3">
                      <af:outputText value="#{row.SetNameLabel}" id="ot5"/>
                    </af:column>
                    <af:column sortProperty="UserName" sortable="true"
                               headerText="#{bindings.EmployeeROVO.hints.UserName.label}"
                               id="c2">
                      <af:outputText value="#{row.UserName}" id="ot4"/>
                    </af:column>
                  </af:table>
For got to add here is the call I'm making via my mbean to grab the current selection in my table:
    private Row getCurrentRowSelection() {
        String employeeIterator = "bindings.EmployeeROVOIterator";
        DCBindingContainer bc = (DCBindingContainer) getBindingContainer();
        return bc.findIteratorBinding(employeeIterator).getCurrentRow();
    }
Binding for my tree.
  <bindings>
    <tree IterBinding="EmployeeROVOIterator"
          id="EmployeeROVO">
      <nodeDefinition DefName="oracle.sysman.core.security.uimodel.view.EmployeeROVO"
                      Name="EmployeeROVO0">
        <AttrNames>
          <Item Value="TargetName"/>
          <Item Value="TargetType"/>
          <Item Value="SetName"/>
          <Item Value="CredGuid"/>
          <Item Value="CredOwner"/>
          <Item Value="CredName"/>
          <Item Value="SetnameNlsid"/>
          <Item Value="SetNameLabel"/>
          <Item Value="IsCredSet"/>
          <Item Value="UserName"/>
          <Item Value="TargetStatus"/>
        </AttrNames>
      </nodeDefinition>
    </tree>
    <action IterBinding="EmployeeROVOIterator"
            id="ExecuteWithParams" RequiresUpdateModel="true"
            Action="executeWithParams">
      <NamedData NDName="QueryTargetName"
                 NDValue="#{viewScope.managedModelBean.targetName}"
                 NDType="java.lang.String"/>
      <NamedData NDName="QuerySetName"
                 NDValue="#{viewScope.managedModelBean.setName}"
                 NDType="java.lang.String"/>
      <NamedData NDName="QueryTargetType"
                 NDValue="#{viewScope.managedModelBean.targetType}"
                 NDType="java.lang.String"/>
    </action>
  </bindings>
Running jdev: 11.1.1.6.0


Also, kind of a side question. Should a table selection even occur on render when table attribute selectedRowKeys="#{bindings.EmployeeROVO.collectionModel.selectedRow}" is set? Otherwise how can I grab a hold of the current selection after the page render?

Thanks in advance for the help,
Wraith

Edited by: wraith101 on Aug 13, 2012 1:43 PM

Edited by: wraith101 on Aug 13, 2012 2:01 PM

Edited by: wraith101 on Aug 13, 2012 4:05 PM
Added in missing binding attribute.

Edited by: wraith101 on Aug 14, 2012 8:39 AM

Comments

953564 Aug 13 2012 — edited on Aug 13 2012
Anyone have any advice on what I'm doing incorrectly here or can point me to a newbie guide on how to use selection handling in ADF? I thought I knew what I was doing but apparently not. This seems like this should just be out of the box functionality.

Page renders -> table renders -> grab current table selection -> enable/disable btn based on selection.
User selects another row -> partial trigger causes btn listening on table to refresh grabbing currently selected row -> enable/disabling btn based on current row selection.

Thanks,
-Wraith

Edited by: wraith101 on Aug 13, 2012 2:29 PM
Srinivas Jilla Aug 13 2012
Hi,

Could you also post the bindings for table binding from pageDefinition.

Thanks,
Srini.
953564 Aug 13 2012 — edited on Aug 13 2012
Moved bindings post up to first post.

Edited by: wraith101 on Aug 13, 2012 4:06 PM
User,

Check this blog to know how to get the selected row from bean.

http://blogs.oracle.com/aramamoo/entry/getting_all_selected_rows_in_adf_table_with_multiple_rows_selection_enabled

-Arun
Frank Nimphius-Oracle Aug 14 2012
Hi,

don't see anything wring in the code you post. To answer your question:

+Should a table selection even occur on render when table attribute selectedRowKeys="#{bindings.EmployeeROVO.collectionModel.selectedRow}" is set? Otherwise how can I grab a hold of the current selection after the page render?+

Table selection events are user events, which means the initial render does not cause a table select event. Anyway, if the command button dynamically determines whether its state is enabled or disabled then you don't need a select event initially. Just have the tesEnabled property GET method accessing the binding layer for the current row

Frank
Frank Nimphius-Oracle Aug 14 2012
Hi,

I tried a testcase. It works for me. Make sure one of the attributes in your view object is defined as a key (checkbox to select)

Frank
953564 Aug 14 2012 — edited on Aug 14 2012
Hi Frank,

Thanks for the replies. I'm not sure I understand what you mean by: "Make sure one of the attributes in your view object is defined as a key (checkbox to select)". Could you point me to an example where this is done?

After thinking about this more are you talking primary key?

-Wraith

Edited by: wraith101 on Aug 14, 2012 7:47 AM
953564 Aug 14 2012 — edited on Aug 14 2012
Hi Frank,
don't see anything wring in the code you post.
I'm assuming when you say wring you mean setting the bind attribute on my table to map to a backing bean as suggested in the link given by Arun?


Thanks,
-Wraith


Ok so I was missing my binding attribute on my table. I added that in, and I checked the VO im using and yes I have a VO attribute set as the key. Testing now to see if this fixes my problems.

Edited by: wraith101 on Aug 14, 2012 8:42 AM
953564 Aug 14 2012
I think something is wrong with the way I am grabbing a hold of the current row in my table. Going to mark this one as not fixed due to ADF user error on my part. Still digging on my end to discover the reason why trying to grab the current row at different times results in the first row data always being returned. Thanks all for your help.
953564 Aug 15 2012
Ok finally coming back to this I believe I have fixed how I am grabbing a hold of the currently selected row from my table. My next question is how can I detect that my page has been rendered and grab a hold of the default selection from within my table when this happens. Is there a way that I can detect when the page has been rendered or when the table has been rendered and call a method from within my mbean to grab a hold of my table and set disable/enabled on my btn?

I found [https://blogs.oracle.com/aramamoo/entry/an_epic_question_how_to] which talks about calling a method on page render but I'm not sure I understand what/how to do what is said here. Any help would be greatly appreciated.


Thanks,
-Wraith
953564 Aug 15 2012 — edited on Aug 15 2012
Ok found a solution to this issue. I added my testBtn state call to the isVisible call in my ManagedBean.tableVisible which was associated by the table attribute listed above: visible="#{ManagedBean.tableVisible}". Seems to be working. so
tableVisible(){
 testEnableDisableBtn(); //used to determine if my btn should be enable/disabled based on current row selection in table
 return true;
}
If anyone has a better solution for this plz advise.

Thanks,
-Wraith

Edited by: wraith101 on Aug 15, 2012 12:55 PM
opthomas Oct 8 2013

Wraith,

How did you fix this. I have a similar issue with a table being populated from a read-only (sql query) view that is called using executeWithParams.

Cheers

Owen

1 - 12
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Nov 5 2013
Added on Aug 13 2012
12 comments
10,923 views