Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Primefaces - Cannot find component with identifier outside the datatable

Tags:

jsf

primefaces

 <ui:define name="content">
    <f:view>                        
    <h:form id="myForm" styleClass="form" >

        <p:dataTable var="provider" id="ss"  value="#{providerSelectBean.providerList}" rowKey="#{provider.license}"  

            selection="#{providerSelectBean.selectedProvider}" selectionMode="single"> 

            <p:ajax listener="#{providerSelectBean.onRowSelect}"    
                            update=":myForm:output"event="rowSelect"/>  

            <p:column sortBy="#{provider.license}" width="110" >
                <f:facet name="header">
                    <h:outputText value="License#" />
                </f:facet>
                <h:outputText value="#{provider.license}" />
            </p:column>

            <p:column sortBy="#{provider.prgName}" width="110" >
                <f:facet name="header">
                    <h:outputText value="Program Name" />
                </f:facet>
                <h:outputText value="#{provider.prgName}" />
            </p:column>

        </p:dataTable><br/>

        <p:panelGrid id="output" >
            <h:outputText value="License" />
            <h:outputText value="#{provider.license}" /> 
        </p:panelGrid>

    </h:form>           
    </f:view>

</ui:define>    

This is my first stint with JSF2.0 and primefaces 3.4.1 and the <p:ajax update gives an error

javax.faces.FacesException: Cannot find component with identifier  
":myForm:output"  referenced from "myForm:ss"
like image 901
user1842840 Avatar asked Nov 21 '12 18:11

user1842840


2 Answers

Try to inspect the generated HTML code and see the actual id being generated for your panelGrid and update that id. If it happens to be dynamic, you can always use the JQuery CSS selectors (I find myself doing that pretty often). In your case, you can go like this:

update="@([id$=output])"

This expression stands for every component whose id ends with output. Take a look at the JQuery docs for more info.

like image 78
Andre Avatar answered Oct 27 '22 23:10

Andre


You can also use :#{p:component(componentId)} as in

<p:ajax listener="#{providerSelectBean.onRowSelect}"  
update=":#{p:component('output')}" event="rowSelect"/>

Quoting BalusC's answer to Get id of parent naming container in template for in render / update attribute:

p:component is a helper function that scans the entire view root for a component with the given ID and then returns its client ID.

like image 22
Can Yegane Avatar answered Oct 28 '22 00:10

Can Yegane