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 isn`t. Normally we should do something like this one in the article: https://andrejusb.blogspot.com/2011/02/how-to-retrieve-adf-select-many-shuttle.html But it didn`t work in my case. For […]

by Valery Borisov

May 19, 2015

2 min read

sci fi web by emilwidlund d5ti5if - 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 isn`t. Normally we should do something like this one in the article:

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

But it didn`t work in my case.

For some reason, calling:

[java]
listBinding.getSelectedValues()
[/java]

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:

[java]
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
[/java]

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

[java]
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
[/java]

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

[java]
for (String numberId : selectedItems) {

}
[/java]


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.

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

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.

[java]
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++;

}

}
[/java]

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

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

Congratulations
You just gained a level!

 

JavaEE and Oracle Developer at Dreamix