26
votes
 <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"
2
You are using the variable provider outside the datatable, where is no longer available.jmrodrigg
<f:view/> is not necessary with <ui:define/>kolossus

2 Answers

29
votes

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.

25
votes

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.