Monday, November 28, 2011

SelectOneChoice ValueChangeListener ProcessUpdates

When value is changed in selectonechoice and you have valuechangelistener associated with it, which has iterator and a variable which captures particular attribute but the problem is in valuechangelistener if you dont specify below line of code you will see that the values are not right (some old selection is captured) hence give this code in valuechangelistener.

valueChangeEvent.getComponent().processUpdates(FacesContext.getCurrentInstance());
e.g of complete method
public void PersonSelected(ValueChangeEvent valueChangeEvent) {

valueChangeEvent.getComponent().processUpdates(FacesContext.getCurrentInstance());
BindingContext bctx = BindingContext.getCurrent();
DCBindingContainer bindings = (DCBindingContainer)bctx.getCurrentBindingsEntry();
OperationBinding opr = (OperationBinding)bindings.getOperationBinding("AllFruitsEP");
Object result = opr.execute();
DCIteratorBinding allFruitsItr = bindings.findIteratorBinding("AllFruits1Iterator");
AttributeBinding personId = (AttributeBinding)bindings.getControlBinding("Personid");
System.out.println("Person ID:"+personId);
System.out.println("Iter size:"+ allFruitsItr.getViewObject().getRowCount());
if (!opr.getErrors().isEmpty()) {
System.out.println("ERROR");
}
}