Daniel B.
Daniel B.

Reputation: 3

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

I am working with many JSF page that includes a summary about the site main subject. On large pages, the summary is repeated in different locations. It is done by defining the element, then inserting it:

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

and later at few different places:

<ui:insert name="sommaireContrat" />

The issue is: the summary has is own backing bean and logic, and every time it is included, the logic is re-executed and a new block of html is rendered. I was wondering if there is a tag which uses a copy of the generated component without involving the bean a second time. I'm open to any suggestion that would not modify the included content.

Upvotes: 0

Views: 55

Answers (1)

Kukeltje
Kukeltje

Reputation: 12337

Omnifaces cache is most suited if you are not using PrimeFaces.

From the Omnifaces showcase:

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

If you are using PrimeFaces, PrimeFaces cache is also an option for you.

From the PrimeFaces site:

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.

There are some differences between them. Read their full documentation to see which is most suited

Upvotes: 1

Related Questions