如何在jsf2中使用h:command ajax刷新窗体外的元素?

时间:2011-11-17 20:29:37

标签: ajax jsf-2

如何通过ajax渲染刷新表单外的元素。

<ui:repeat var="o">
    <h:form>
        <h:panelGroup id="someid">
       ...
        </h:panelGroup>

        <div>
            <h:commandButton action="#{o.doSomething}">
                <f:ajax event="action" render="someid :rehreshthistoo" />
            </h:commandButton>
        </div>
    <h:form>
</ui:repeat>

 <h:panelGroup id="rehreshthistoo">
       ...
 </h:panelGroup>

1 个答案:

答案 0 :(得分:6)

您的代码看起来很好。如果<h:panelGroup id="rehreshthistoo">另一个 UINamingContainer组件中已经单独使用,并且如果您尚未更改默认的JSF,那么会工作将:的容器分隔符命名为其他内容,例如_-

最终的答案应该在JSF生成的HTML源代码中找到。在浏览器中打开页面,右键单击查看源,在其中找到<span>生成的<h:panelGroup id="rehreshthistoo">元素,然后在<f:ajax render>中使用其完整ID命名容器分隔符作为前缀。如果它包含某个UINamingContainer父项的自动生成ID,那么您也应该为该父组件提供固定ID。

另见: