15 October 2010

TROUBLESHOOTING: Reset the values of the UI components in order to get refreshed from model

Problem 
We have a af:popup that its value should be cleared its time it was raised.
The fields of the popup were based on transient attributes of SQL Based VO.
For that reason each time the popup was raise the VO was executed (to take its initial values)
The problem was that in hte popup the values were not cleared.

Solution
 I came across this excellent post
http://adfbits.blogspot.com/2008/11/sticky-popup-values.html
 Using the following method after executing the SQL based VO (below is the function a bit modifying):
public void resetStaleValues(UIComponent rootComponent){
  Iterator iter = rootComponent.getFacetsAndChildren();
  while (iter.hasNext()) {
   UIComponent component = iter.next();
   if (component instanceof UIXEditableValue) {
     UIXEditableValue uiField = (UIXEditableValue)component;
   uiField.resetValue();
   //a little mod here: Also refesh the component
   RequestContext.getCurrentInstance().addPartialTarget(uiField);

  }
   resetStaleValues(component);
}

You can also enrich  your code by including functinality to set value null with methods like:

No comments:

Post a Comment

You might also like:

Related Posts Plugin for WordPress, Blogger...