Determining Selected Table In ADF Faces

There are many niceties that JDeveloper/ADF provides, but as all things in programming and in life, the 80/20 rule typically applies. Putting master and detail tables on a page and syncing the two is a relatively easy process. You create the form, make sure that the selection listener on the table is set to use the data control to execute “makeCurrent” on the view, and set the detail table to do a partial page refresh based on the id of the master table. It’s great that it is such an easy thing to accomplish.

What isn’t great is what you need to do to actually determine which table is selected on the page all because of a quirk in the selection event on the table itself. It seems the selection listener only gets called when the selection in the table changes. So, if you select row 1 from table A, then select row 2 from table B, if you go back and select row 1 from table A again, the selection listener doesn’t get called because it was the same row that was originally selected. This makes it more challeging than simply adding code to the selection listener.

To keep track of the table that is selected, I elected to create a hidden input variable on the page, and then a javascript function that updated that variable with a parameter that is passed in. That function is then called by the selection listener.

The javascript funtion looks like this:

function tableClicked(var value) {
var selected = document.getElementById(”selectionMade”);
selected.value = value;
}

The hidden input value on the page is then tied to a backing bean. The method that needs to make a decision based on which table is selected simply checks the selectionMade value of the backing bean.

In order to get the table to call the javascript function, go to the source of the JSP file and add the following:

<af:clientListener method=”tableClicked(’tab1′)” type=”click”/>

One thing to look out for is that this particular way of doing things will not work if you want to check the value of the backing bean from an action that is performed with imediate=”true”.

Share/Save/Bookmark

Related posts:

  1. Adding a Checkbox to an ADF 11g Table SQL, at least the standard SQL and the SQL that...
  2. How To Create A Master-Detail Page in ADF 11g This article builds upon the last article in which we...
  3. How To Create An Editable List Page in ADF 11g For those of you wondering how my presentation turned out...

Leave a reply

You must be logged in to post a comment.