5

我想通过 PPR 更新页面的一部分。这是我要更新的页面部分:

 <h:panelGroup id="aggiungiAuto"
                  rendered="#{!autoBean.operazioneOk}">
        <ui:include src="../component/aggiungi_auto.xhtml"/>
 </h:panelGroup>

虽然这是 aggiungi_auto.xhtml 中的 commandButton

 <p:commandButton value="Submit"
                  update="growl aggiungiAuto aggiungiFoto"
                  actionListener="#{autoBean.insert}"/>

任何的想法?

4

2 回答 2

7

JS/Ajax 在客户端工作,而不是在服务器端。JSF 在服务器端工作,而不是在客户端工作。当您指示 JSF 不将组件呈现为 HTML 时,客户端将不存在任何内容,因此 JS/Ajax 将无法找到要刷新/更新的 HTML 元素。

您需要将其包装在另一个<h:panelGroup>.

<h:panelGroup id="aggiungiAuto">
    <h:panelGroup rendered="#{!autoBean.operazioneOk}">
        <ui:include src="../component/aggiungi_auto.xhtml"/>
    </h:panelGroup>
</h:panelGroup>

这样,客户<span id="aggiuniAuto">始终存在,因此 JS/Ajax 将能够使用 JSF 生成的新 HTML 数据对其进行更新。

于 2010-12-27T21:47:26.923 回答
3

所以我遇到了 PrimeFaces 的这种问题(这次上面的答案还不够),我也找到了一个解决方案。

我认为部分问题是我在ui:include递归使用。无论出于何种原因,PrimeFaces 不合理地导致 UI 组件绑定到后端数据不同步;例如,当单击“添加”按钮时,将在 UI 中创建一个新值,但随后会从下面部分的值中删除它的数据,等等......


说明?“[O] 一个 viewscoped bean,一个隐藏字段被添加到表单中以保存回发数据 [;] 如果该字段不包含在流程中,那么 bean 将丢失上下文。” ui:include这个特殊问题在递归中尤其普遍。解决方案(所有关于p:commandButton或其他可操作的组件):

  • 确保updateandprocess指向一个 JSF 组件,而不是一个常规的 HTML 组件。
  • update如果下一个范围中断(与绑定不同步)。
  • 使用styleClass's 进行更新(不是例如 PF ID 或@this:@parent其他东西),以便使用 jQuery 而不是 PF,例如:@(.fieldset-class).
  • process whatever scope is being updated. (This is needed for the post-back data so that the Bean keeps its context for the update...) process="@this" is not needed here, provided that the button is contained by the process value component.
  • For all buttons without validation wanted, set immediate="true".
  • If none of the above works (which happened with the Add buttons, probably due to ui:include recursion), set process="@this", immediate="true", and update="@none", and then oncomplete="remoteCommandName();", and have a p:remoteCommand instead with that name with the process, immediate, and update mentioned in the above points.
  • ui:include如果上述方法均无效(与其他一些按钮一起发生,可能是由于在递归中的另一层更深)...环绕h:panelGroup下一个c:forEach,然后更新按钮本身的PrimeFaces ID,同时保持其之后调用,如上所述。remoteCommand
  • 如果以上都不起作用(这又发生在我身上)......试试下面的代码:
    • p:commandButton(s)oncomplete="$('.FixButtonSC').click();"
    • p:fieldset带有样式类的 FieldsetSC 中:
          <!-- Fix (hidden) button. -->
          <p:commandButton id="FixButton" styleClass="FixButtonSC"
            process="@this" update="@(.FieldsetSC)" style="display: none;" />

希望有帮助...

于 2018-10-26T19:21:33.623 回答