MultiSelectChoice: How to get underlying values selected

Let's say you include a multiselectchoice component in your jspx/jsff page, which has <f;selectItem> or <af:forEach> binded to a VO iterator to populate the multiselectchoice and the value property of which is binded to a List attribute binding.

When the user selects some items in that choice List then u want the actual values to be posted.You can check the valuepassthrough flag to true , but many a times it doesn't help and you end up getting the indexes of multiselect values.

Here is a way to get the actual values..

Lets say in the bean u have a utility method to achieve this as follows..

You can associate a valueChangeListener for the multiselectchoice as follows..

public void onValueChangeOfLOV(ValueChangeEvent valueChangeEvent) {
       //get array of indexes of selected items in master list
       List valueIndexes = (List)valueChangeEvent.getNewValue();
       String concatCodes = 
returnSelectmanyChoiceValues(valueIndexes,"YourIterator", 
"YourAttribute");       
   }

   public String returnSelectmanyChoiceValues(List valueIndexes,String 
iterName, String idAttrName){
          DCBindingContainer dc = 
(DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
          DCIteratorBinding iter = dc.findIteratorBinding(iterName);
          ViewObject vo = iter.getViewObject();

          String codes = "";

          for(Object index : valueIndexes){
              String iIndex = (String)index;
              Row row  = vo.getRowAtRangeIndex(Integer.parseInt(iIndex));
              codes = codes +(String)row.getAttribute(idAttrName)+",";
          }
          //remove last ","  
          if(codes.endsWith(","))
              codes = codes.substring(0,codes.lastIndexOf(","));
          return codes;
   }

This will return u a comma separated values of the selected items. if you want then
You can store it in a List.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Talk on ADF (Mail To: vijay.x.mohan@oracle.com)

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today