user489041
user489041

Reputation: 28294

JSF's ui:include not working as expected

I have a dialog that is created using PrimeFaces like so:

<h:body>
    <ui:composition>
    <h:form id="newResource">
        <p:dialog 
            id="modalDialog" 
            header="Create a new Resource" 
            widgetVar="dlg2" 
            modal="true" 
            visible="true">  
            ...
        </p:dialog>
    </h:form> 
    </ui:composition>  

In the page where I want this to be displayed in, I have the following cod. The last line is where I include the dialog.

    <h:body>
    <p:growl id="growl" showDetail="true" sticky="true" />
    <ui:composition template="/template/masterLayout.xhtml">
        <ui:define name="windowTitle">
            Resources
        </ui:define>
        <ui:define name="stack">
            <p:stack 
                id="dvStackMenu" 
                expanded="true" 
                icon="/resources/images/stack/stack.png" 
                model="#{resourcePageController.stackMenuModel}"/>
        </ui:define>
        <ui:define name="content">
            <h:form>
                <p:dataTable 
                    var="resc" 
                    rowKey="#{resc.resourceId}"
                    selection="#{resourcePageController.selectedResources}"
                    value="#{resourcePageController.resources}"
                    selectionMode="multiple">  
                    <p:column headerText="Name">  
                        <h:outputText value="#{resc.name}" />  
                    </p:column>
                    <p:column headerText="Created On">  
                        <h:outputText value="#{resc.createdOn}" />  
                    </p:column>
                    <p:ajax event="rowSelect"/>
                    <p:ajax event="rowUnselect" />
                </p:dataTable> 
            </h:form>
        </ui:define>
    </ui:composition>
    <ui:include src="/template/dialog/create/resource.xhtml" />
</h:body>

The dialog's visible attribute is set to true, so the expected behavior is when the page loads, the dialog should be displayed. This howver is not the case.

If I navigate to /template/dialog/create/resource.xhtml in my browser, the dialog is displayed as expected.

Can any one assist me in what is going on? I am not sure if it is my use of the ui:include or something else is going on.

Upvotes: 0

Views: 2333

Answers (1)

axtavt
axtavt

Reputation: 242686

When content of <ui:composition> is decorated with its template, all content outside of <ui:composition> is ignored.

Therefore you need to place your include inside one of <ui:define>s.

Upvotes: 3

Related Questions