2013-03-18 56 views
1

我们正在将应用程序从jsf 1.2迁移到jsf 2.0,并将Ajax4JSF(ajax4jsf-1.1.1)升级到Richfaces 4.2.2。 在我们的旧代码中,有些地方使用org.ajax4jsf.framework.ajax.AjaxActionComponent以编程方式设置某些组件的'rerender'属性。相关代码如下:Richfaces 4 - 替代AjaxActionComponent

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

但在RichFaces的4 AjaxActionComponent类中删除。 是否有一个类可以用来代替AjaxActionComponent,或者以其他方式通过编程方式更改UIComponent的'rerender'属性?

回答

1

在JSF2中,有一种更通用的方法来使用PartialViewContext对象以编程方式呈现ID。请尝试以下代码片段

 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"); 
     } 
+0

所以,我不应该将id的渲染与UIComponent的相关联,而是使用PartialViewContext来代替? – Rony 2013-03-19 16:49:10

+0

@Rony正是由于JSF2的半本地ajax支持; Ajax处理不再是独立于组件的(至少在服务器端) – kolossus 2013-03-19 18:41:59