Monday, November 1, 2010

ADF UI - Getting updated values in valueChangeListener methods

We use valueChangeListener for different ADF components like radio buttons (af:selectOneRadio), choicelists (af:selectOneChoice) and list of values ie., LOVs (af:inputComboboxListOfValues), etc., But, when you try to get the value of the attribute in the valueChangeListener method, you'll end up in getting old value but not the latest updated value. You need to call the processUpdates method to get the updated values.


Sample usage in valueChangeListener method:
public void copyPresentAddress(ValueChangeEvent vce){ vce.getComponent().processUpdates(FacesContext.getCurrentInstance()); Boolean sameAsPresentAddress = sameAddressCheckbox.isSelected(); if(sameAsPresentAddress){ ADFUtil.invokeEL("#{bindings.copyPresentAddress.execute}"); } else{ ADFUtil.invokeEL("#{bindings.resetPermanentAddress.execute}"); } }

But, if you're interested in getting both old as well as new values, you can use the methods getOldValue() and getNewValue() of valueChangeEvent.

Sample Method:
public void copyPresentAddress(ValueChangeEvent vce){ String oldValue =(String) vce.getOldValue(); String newValue = (String) vce.getNewValue(); if("residence".equals(newValue)){ //logic to render residence address region } }


Related Posts with Thumbnails