0

I have seen the question asked about how to rectify the component update code while migrating to Primefaces 3.1, preventing the exception

Cannot find component with identifier "...." in view.

But how to update a component that is not enclosed by a form element ? Such as I need to update, using remote command, the following ouputPanel:-

<p:outputPanel id='messageBox''> ... </p:outputPanel> 

Using : Primefaces 3.1 with JSF 2.1.6

2 Answers 2

2

Just reference it by its absolute client ID instead. The update attribute is by default relative to the current UINamingContainer component (the <h:form> is such one). Assuming that the given <p:outputPanel> is by itself not inside any other UINamingContainer component, then just use update=":messageBox".

<p:commandButton ... update=":messageBox" /> 

If you're not sure, then you need to open the page in browser, do View Source and locate the generated HTML element of <p:outputPanel id="messageBox"> in there, take the exact value of its id attribute and then prefix it with the default naming container separator :.

Sign up to request clarification or add additional context in comments.

4 Comments

I don't too much prefer directly using JSF generated id, seeing from source, as that changes on making minor changes in the page code. Should I instead use the binding approach as described in your answer here: stackoverflow.com/questions/7970268/…
Just give all UINamingContainer components a fixed ID. E.g. <h:form id="foo">. This way JSF won't autogenerate one for them.
Thanks.. but I am still curious as to why the binding approach isn't preferred rather than giving ids to all components? :)
Because it's unnecessarily more complicated. Try to do at its simplest first. Otherwise any future developer / code reviewer might wonder "why the heck" you're using binding instead of id there.
0

Specify an unique id for the "<h:form>" component, then use like below code to update a component

udpate="@(#messageBox)" 

1 Comment

Please explain why the OP should give the form an unique ID and please also explain why the OP should use PFS instead of a normal client ID for this.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.