0

Just like ui:include can be dynamic by calling the src as so

<h:form id="form">

    <p:outputPanel id="title" value="This is the main xthtml page">

    <p:dialog header="Modal Dialog" modal="true">

        <ui:include src="#{mainBacking.compositePage}">
            <ui:param name="action" value="actionOne" />
        </ui:include>

    </p:dialog>

</form>

I want to call composite component by the source. One issue in ui:include is it cannot pass methods as parameters while composite components can. How do I create/call a dynamic composite component based on the src? The current approach is I need to specify all the composite components in the same xthml file as so (of course, this is only the minimum reproducible code, the real one is much longer with more parameters);

<h:form id="form">

    <p:outputPanel id="title" value="This is the main xthtml page">

    <p:dialog header="Modal Dialog" modal="true">

        <util:user-composite id="userModaL"
        bean="#{userBean}"></util:user-composite>

        <util:company-composite id="companyModaL"
        bean="#{companyBean}"></util:company-composite>

        <util:education-composite id="educationModaL"
        bean="#{eduBean}"></util:education-composite>

    </p:dialog>

</form>

But this means, on page load, all the beans will be called and initialized. I don't want that as the system will be heavy on page load. I want it to call a composite based on need and only initializes and show it then just like ui:include. How do I do so using composite components and is it possible? If not, are there other solutions?

  • 2
    I have some difficulty understanding your question. What do you mean by _"I want to call a composite component by source"_? and what is _" want it to call a composite based on need and only initializes and show it then just like ui:include."_? Initializing beans is done by you... Do that lazy then, in e.g. a getter instead of a `@PostConstruct` or (worse) a constructor... – Kukeltje Dec 23 '19 at 10:40
  • **"I want to call a composite component by source"** Meaning that instead of dumping all the composites I want to use in one xhtml file as shown in the code snippet, I want to dynamically call the composite component based on the criteria. So basically when I am interacting with the user class, I want the composite component to only call the user-composite composite component. Other unrelated beans should not be initialized until called. Currently, when the approach in the code snippet is followed, all the beans are initialized on page load as the beans are called and used in the xhtml file. – Nik Mohamad Lokman Dec 24 '19 at 01:32
  • **"Do that lazy then, in e.g. a getter"** May I know what do you mean by this @Kukeltje ? – Nik Mohamad Lokman Dec 24 '19 at 01:39
  • I have updated the code snippet for you to better understand the situation @Kukeltje – Nik Mohamad Lokman Dec 24 '19 at 01:49

0 Answers0