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

Rajat Gupta
  • 25,853
  • 63
  • 179
  • 294

2 Answers2

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 :.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • 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: http://stackoverflow.com/questions/7970268/using-one-component-datatable-id-inside-composite-component – Rajat Gupta Mar 12 '12 at 12:59
  • Just give all `UINamingContainer` components a fixed ID. E.g. ``. This way JSF won't autogenerate one for them. – BalusC Mar 12 '12 at 13:01
  • Thanks.. but I am still curious as to why the binding approach isn't preferred rather than giving ids to all components? :) – Rajat Gupta Mar 12 '12 at 14:16
  • 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. – BalusC Mar 12 '12 at 14:29
0

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

udpate="@(#messageBox)"
John Dvorak
  • 26,799
  • 13
  • 69
  • 83
  • 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. – BalusC Feb 19 '13 at 11:27