Tuesday, June 26, 2012

Getting the value of list

Hello, Everyone;
a while age I had to use select one choice to filter a record set then display in a table.
there are multiple approaches that could be used here but what I ended up using was:
list binding+select one choice+valueChangeEvent.

the problem that I faced was how to get the selected value?
Some people said use the binding property to bind to the backing bean then set the valuePassThru =true so that getValue() return wanted value but for some reason or another it did not work.

eventually fund some workarounds to be inserted into the backing bean's valueChangeEvent method


1)
public void DeptListChangeEvt(ValueChangeEvent valueChangeEvent) {
     
BindingContainer container=BindingContext.getCurrent().getCurrentBindingsEntry();
 JUCtrlListBinding list =  (JUCtrlListBinding)container.get("DepartmentName");

valueChangeEvent.getComponent().processUpdates(FacesContext.getCurrentInstance());
      System.out.println(((Row)list.getSelectedValue()).getAttribute(1));
    }




2)
public void DeptListChangeEvt(ValueChangeEvent valueChangeEvent) {


       BindingContainer container=BindingContext.getCurrent().getCurrentBindingsEntry();
       DCIteratorBinding iter =container.findIteratorBinding("departmentLOVIterator");


       Row row=iter .getRowAtRangeIndex((Integer)(valueChangeEvent.getNewValue());
        System.out.println(row.getAttribute(0));
      
    }

3)

public void DeptListChangeEvt(ValueChangeEvent valueChangeEvent) {

       
       RowSetIterator rowSetIt=  list.getListRowSetIterator();
        Row x= rowSetIt.getRowAtRangeIndex((Integer)valueChangeEvent.getNewValue());
     
        System.out.println("list iterator");
        System.out.println(x.getAttribute(0));
      
    }

if you simply want to get the value aproach 1 is good, but if there is some logic that depends on the the new and old value then you use either 2 or 3.




No comments:

Post a Comment