如何在不重新生成元素的情况下插入元素的精确副本

How to insert an exact copy of an element without regenerating it

我正在处理许多 JSF 页面,其中包含有关站点主要主题的摘要。在大页面上,摘要在不同位置重复。它是通过定义元素,然后插入它来完成的:

<ui:define name="sommaire">
 <ui:include src="/sommaire/sommaire.xhtml">
  <ui:param name="contrat" value="#{form.contrat}" />
 </ui:include>
</ui:define>

之后在几个不同的地方:

<ui:insert name="sommaireContrat" />

问题是:summary有自己的backing bean和逻辑,每次包含它时,都会重新执行逻辑并渲染一个新的html块。我想知道是否有一个标签使用生成的组件的副本而无需第二次涉及 bean。 我愿意接受任何不会修改包含内容的建议。

如果您不使用 PrimeFaces,

Omnifaces cache 最适合。

来自 Omnifaces 展示:

The <o:cache> component allows to cache a fragment of rendered markup. The first request for a page that has this component on it will cause this markup to be put into the cache. Then for subsequent requests the cached content is used directly and none of the components, backing beans and services that were used to generate this content in the first place will be consulted

如果您使用 PrimeFaces,PrimeFaces cache 也是您的一个选择。

来自 PrimeFaces 网站:

Cache Cache component is used to reduce page load time by caching the content in a global cache after the initial rendering. Various cache providers are supported like ehcache and hazelcast. In this example, toolbar component is cached and output would be retrieved from cache.

它们之间存在一些差异。阅读他们的完整文档,看看哪个最适合