Kishor Prakash
Kishor Prakash

Reputation: 8171

How to update Primefaces component in one page from command button in another page when both pages are included in one page

I have 2 pages

input.xhtml

<h:form>
    <p:panelGrid>
        <p:row>
            <p:column>
                <h:outputText value="Name : "/>
            </p:column>
            <p:column>
                <p:inputText id="name" value="#{inputBean.name}"/>
            </p:column>
        </p:row>
        <p:row>
            <p:column colspan="2" >
                <p:commandButton action="#{inputBean.buttonAction}" value="Submit"/>
            </p:column>
        </p:row>
    </p:panelGrid>
</h:form>

display.xhtml

<h:form id="form1">
    <h:outputText value="#{inputBean.name}" id="dis123"/>
</h:form>

If I include both of them in a single page like below

index.xhtml

<p:accordionPanel widgetVar="main" multiple="true">
    <p:tab title="Input">
        <ui:include src="input.xhtml"/>
    </p:tab>

    <p:tab title="Output">
        <ui:include src="display.xhtml"/>
    </p:tab>
</p:accordionPanel>

can I call update="dis123" from command button in input.xhtml?

Upvotes: 6

Views: 47305

Answers (1)

BalusC
BalusC

Reputation: 1109272

No, you can't. A relative client ID like update="dis123" basically searches in the same NamingContainer parent component which is in your case the <h:form> of the first page. However, no such component exist. It's actually in a different NamingContainer parent. You need to provide an absolute client ID instead: update=":form1:dis123".

For starters, an easy way to figure the right absolute client ID is by just looking in the JSF-generated HTML output (rightclick, View Source in browser) for the generated HTML element ID of the desired component and then prefix it with :.

Please note that this all has nothing to do with includes. You'd have had exactly the same problem when having all the code in a single page.

See also:

Upvotes: 19

Related Questions