3

I have the following UI Primefaces snippet:

<pou:growl id="growl" 
               redisplay="false"
               showDetail="false" 
               sticky="false" />

When I try to update this item, for example like this:

<pou:commandButton value="Update" 
                   update=":growl"/>

Everything works fine.

When I move growl to a composite component however and try to call it (ie. like this):

<ez:growl/>

I get an error maessage that says:

javax.faces.FacesException: Cannot find component with identifier ":growl" referenced from "j_idt84:j_idt85:testForm:j_idt111".

My question is why are all these auto generated names being added and how can I control them so I can actually access the components to update?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
tarka
  • 5,289
  • 10
  • 51
  • 75

1 Answers1

14

It's because composite components inherently extend from UINamingContainer (like as <h:form>, <h:dataTable>, etc) and thus prepend the client ID of their children with own ID.

To achieve your particular functional requirement, first give your composite component a fixed ID:

<ez:growl id="growl"/>

Then embed the <p:growl> in the composite component's implementation in a plain HTML container element like <div> or <span> with the composite component's client ID as element ID:

<cc:implementation>
    <span id="#{cc.clientId}">
        <p:growl />
    </span>
</cc:implementation>

Now you can just use update=":growl" the usual way.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I have the same problem, and I didn't understand exactly how to apply your answer : I have one component included inside of another xhtml, inside of a . Can you please tell me how to addapt to my case ? Thanks ! – Ioan Feb 19 '13 at 15:53
  • @loan: Are you using a composite component or not? (as in, you're using `` and `` where `cc` is from `http://java.sun.com/jsf/composite`). – BalusC Feb 19 '13 at 15:55
  • No, I have a simple main.xhtml, containing , and one , and inside of one of the I do : . This form is inside of a . That's all. It worked until I added menu tab view part.. – Ioan Feb 19 '13 at 15:59
  • 1
    @loan: Then the answer don't apply to you at all. Continue searching or ask a new question. In the meanwhile, this general answer may apply if you're facing the error message mentioned in the question: http://stackoverflow.com/questions/8634156/how-to-reference-components-in-jsf-ajax-cannot-find-component-with-identifier/8644762#8644762 – BalusC Feb 19 '13 at 16:00