【问题标题】:Richfaces 4 - substitute for AjaxActionComponentRichfaces 4 - 替代 AjaxActionComponent
【发布时间】:2013-03-18 20:08:16
【问题描述】:

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

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' 属性?

【问题讨论】:

    标签: jsf migration richfaces ajax4jsf


    【解决方案1】:

    在 JSF2 中,有一种更通用的方法可以使用 PartialViewContext 对象以编程方式呈现 id。试试下面的sn-p

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

    【讨论】:

    • 那么,我不应该将要呈现的 id 与 UIComponent 相关联,而是与 PartialViewContext 相关联?
    • @Rony 正是由于 JSF2 的半原生 ajax 支持; Ajax 处理不再完全依赖于组件(至少在服务器端)
    猜你喜欢
    • 2011-12-30
    • 2018-04-07
    • 2021-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-29
    • 2013-12-19
    相关资源
    最近更新 更多