navigation

ADF Adventurers Only.Retrieve af:selectOrderShuttle selected value.

ADF Adventurers Only.Retrieve af:selectOrderShuttle selected value.

Greetings fellow ADF Adventurers. Let me share you some of my experience, so you can level-up faster.

The case

Recently I had to use the af:selectOrderShuttle. I supposed this to be straightforward, but it isnt. Normally we should do something like this one in the article:

http://andrejusb.blogspot.com/2011/02/how-to-retrieve-adf-select-many-shuttle.html

But it didnt work in my case.

For some reason, calling:

listBinding.getSelectedValues()

was not preserving the user selection.

The solution

Initially everything is as normal. We have some ViewObject,  let us say TaskТеmplateVO added to Application Module.

We drag it on the page as af:selectManyShuttle

ВАЛЕРИ  1

We select the Id attribute while we show the Name attribute to the user.

Валери 2

 

The default drag options is af:selectManyShuttle, which we change later on to af:selectOrderShuttle

The result is:

af:selectOrderShuttle value="#{bindings.TaskTemplateVO.inputValue}"
                         	leadingHeader="List 1"
                         	trailingHeader="List 2"
                         	valuePassThru="true" id="sms2
    	f:selectItems value="#{bindings.TaskTemplateVO.items}" id="si1"/
/af:selectOrderShuttle

We will change that so we have our selection available in Managed Bean.

af:selectOrderShuttle value="#{pageFlowScope.TestBean.selectedItems}"
                         	leadingHeader="List 1"
                         	trailingHeader="List 2"
                         	valuePassThru="true" id="sms2"
    	f:selectItems value="#{bindings.TaskTemplateVO.items}" id="si1"
/af:selectOrderShuttle

So far, everything is ok. We can iterate over the selection and we can retrieve the user selection.

for (String numberId : selectedItems) {

    }


Issue

But there is one issue, the selection holds the index of the selection.

Not Id, not Name, it holds index!

valuePassThru=”true” does not seem to work. What can we do about that and retrieve the real value that we need?

Issue solution

Approach 1
We can access the iterator that we have in the Page Definition, and retrieve the row by an index.

for (String numberId : selectedItems) {
Row row =
ADFUtils.findIterator("TaskTemplateVOIterator").getRowAtRangeIndex(numberId );
….
)

Approach 2

We will create a map when the page loads and store the values that interest us in it.

In this case, we will create a map containing Index and Id.

public TestBean() {
super();
ADFUtils.findIterator("TaskTemplateVOIterator").setRangeSize(-1);
Row[] taskTemplateRows =
ADFUtils.findIterator("TaskTemplateVOIterator").getAllRowsInRange();
int index = 0;
for (Row row: taskTemplateRows){

TaskTemplateVORowImpl rowImpl = (TaskTemplateVORowImpl)row;
//System.out.println("putting" + new Number(index) + " id " +  rowImpl.getId()  );
allHeaderTasks.put(Integer.toString(index), rowImpl.getId());
index++;

}

}

And now whenever we need to return the selected Id-s we can do this:

for (String numberId : selectedItems) {
System.out.println("getting " + allHeaderTasks.get(numberId));</i>
}

Congratulations
You just gained a level!

 

Valery Borisov

JavaEE and Oracle Developer at Dreamix

More Posts - Website

Follow Me:
LinkedIn

Do you want more great blogs like this?

Subscribe for Dreamix Blog now!

  • Anonymous

    Many Thanks!

  • Anonymous

    Very informative.
    Thanks :-)

  • Ahmad Abutalib

    I face issues like these in ADF all the time. The documentation says it has to work but it does not and end up creating a workaround instead.