仅重新渲染面板的一部分

时间:2012-11-22 10:03:18

标签: richfaces jsf-1.2 ajax4jsf

这是我的问题的简化版本。

<h:form id="form1">
  <a4j:commandButton value="Ok" reRender="panel_1"/>

  <a4j:outputPanel id="panel_1" layout="block" style="height:100px;border:solid 1px;">
    Content here should be reRendered

    <a4j:outputPanel id="panel_2" layout="block" style="height:50px;border:solid green;color:green;">
      Content here should not be reRendered  
    </a4j:outputPanel>

  </a4j:outputPanel>
</h:form>

当用户点击<a4j:commandButton>时,应重新审核第一个<a4j:outputPanel>(panel_1)。但是第二个<a4j:outputPanel>内的内容不应该重新生成。这可能吗? (至少通过将<a4j:outputPanel>更改为另一个组件。)

2 个答案:

答案 0 :(得分:0)

如果要将要重新呈现的内容包装在另一个面板中呢?像这样:

<h:form id="form1">
  <a4j:commandButton value="Ok" reRender="panel_1_a"/>
  <a4j:outputPanel id="panel_1" layout="block" style="height:100px;border:solid 1px;">

    <a4j:outputPanel id="panel_1_a">
      Content here should be reRendered
    </arj:outputPanel>

    <a4j:outputPanel id="panel_2" layout="block" style="height:50px;border:solid green;color:green;">
      Content here should not be reRendered  
    </a4j:outputPanel>

或者,您可以将panel_2移到其他地方。

答案 1 :(得分:0)

您可以使用MyFaces来改进Makhiel解决方案,它允许您定义子表单以包装部分内容以进行部分验证和模型更新。

MyFaces还允许您通过属性<t:commandButton><t:subform>附加到特定actionFor=""

您需要包含tomahawk库以使用其标签:

<%@ taglib prefix="t" uri="http://myfaces.apache.org/tomahawk"%>

然后Makhiel的代码可以通过这种方式重写(我正在移动<a4j:outputPanel>内的按钮,以便将其放在<t:subform>标记内。

<h:form id="form1">
    <a4j:outputPanel id="panel_1" layout="block" style="height:100px;border:solid 1px;">
        <t:subform id="FirstPanelForm">
            <t:commandButton value="Ok" reRender="panel_1_a" actionFor="FirstPanelForm"/>
            <a4j:outputPanel id="panel_1_a">
                Content here should be reRendered
            </a4j:outputPanel>
        </t:subform>
        <a4j:outputPanel id="panel_2" layout="block" style="height:50px;border:solid green;color:green;">
            Content here should not be reRendered  
        </a4j:outputPanel>
    </a4j:outputPanel>
</h:form>

我不知道这是你正在寻找的行为。如果没有,请坚持subform的想法并尝试在您的代码中使用它。