Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 262
Kishor Prakash Avatar asked Jan 21 '13 12:01

Kishor Prakash


People also ask

What is PrimeFaces autoupdate?

PrimeFaces AutoUpdate. In one of our PrimeFaces powered applications, we use a single growl component placed in a template of the application. All application wide messages are displayed using this growl so each page using the template does not need to define it every time. Problem is on every page we need to update this growl component for most...

What is partial page rendering in PrimeFaces?

PrimeFaces provides a partial page rendering ( PPR) and view-processing feature based on standard JSF 2 APIs to enable choosing what to process in the JSF lifecycle and what to render in the end with AJAX. PrimeFaces AJAX Framework is based on standard server-side APIs of JSF 2.

What is PrimeFaces Ajax?

PrimeFaces AJAX Framework is based on standard server-side APIs of JSF 2. On the client side, rather than using the client-side API implementations of JSF implementations, such as Mojarra and MyFaces, PrimeFaces scripts are based on the jQuery JavaScript library.

What is PrimeFaces based on?

On the client side, rather than using the client-side API implementations of JSF implementations, such as Mojarra and MyFaces, PrimeFaces scripts are based on the jQuery JavaScript library. How to do it...


1 Answers

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:

  • How to find out client ID of component for ajax update/render? Cannot find component with expression "foo" referenced from "bar"
like image 158
BalusC Avatar answered Oct 08 '22 18:10

BalusC