Monday, December 7, 2009

JSF Ajax reRender Issue

While Re-rendering ajax region certain fields are not re-rendered properly, even though the bean/controller has the current and perfect data, that is because the component tree needs to be re-build to get that. which could be done by
In Page:
[h:commandButton]
     [a4j:support id="refreshBtnAjax" event="onclick"                               
        actionListener="#{Controller.clearData}"
        reRender="panelGroupToRefresh" immediate="true"/]
                          Re-Render
[/h:commandButton]

In Controller/ Backing Bean:
Find the component in the page that needs to be re-rendered and clear it from the component tree so that, it could be rebuilt.
public void clearData(final ActionEvent event){
   Place your business logic here
  
   final UIComponent component =
        FacesContext.getCurrentInstance().getViewRoot()
             .findComponent("form:panelGroupToRefresh");
   if (component != null) {
      component.getChildren().clear();
   }
}
This helps to re-render or refresh the data immediately when we press the button or refresh data at regular interval of time, which ever is preferred.

No comments:

Post a Comment