1

We are migrating an application from jsf 1.2 to jsf 2.0, and upgrading Ajax4JSF (ajax4jsf-1.1.1) to Richfaces 4.2.2. In our old code, there are places where we use org.ajax4jsf.framework.ajax.AjaxActionComponent to programmatically set the 'rerender' attribute of some components. The relevant code is as follows:

public void changeReRender(UIComponent comp){
    AjaxActionComponent commandAjax = (AjaxActionComponent)comp;
    HashSet values = new HashSet();
    values.add("idToBeRerendered");
    commandAjax.setReRender(values);
}

But in Richfaces 4 the AjaxActionComponent class was removed. Is there a class that can be used instead of AjaxActionComponent, or another way to programmatically change the 'rerender' attribute of UIComponent?

Rony
  • 45
  • 9

1 Answers1

1

In JSF2, there's a more generic approach to programmatically rendering ids using the PartialViewContext object. Try the following snippet

      public void changeReRender(UIComponent comp){
            // AjaxActionComponent commandAjax = (AjaxActionComponent)comp;
            // HashSet values = new HashSet();
            // values.add("idToBeRerendered");
            // commandAjax.setReRender(values);
           FacesContext context = FacesContext.getCurrentInstance();
           PartialViewContext partialContext =  context.getPartialViewContext(); //obtain a reference to the PartialViewContext object
           //add the desired id to the list of render ids 
           partialContext.getRenderIds().add("idToBeRerendered");
        }
kolossus
  • 20,559
  • 3
  • 52
  • 104
  • So, I should not associate the id's to be rendered with the UIComponent's, but with the PartialViewContext instead? – Rony Mar 19 '13 at 16:49
  • @Rony precisely, thanks to JSF2's semi-native ajax support; Ajax handling is no longer exclusively component dependent (at least on the server side) – kolossus Mar 19 '13 at 18:41