PrimeFaces – where are my widgets?

Widget for varWidget for var ‘dlg’ not available!

The Tears

Does that fuel you with a deep, burning rage? Widgets not being available are insanely frustrating, especially because deep down you know it’s going to be because of a stupid mistake.

A quick Google for the error message brings up several different potential reasons — duplicate inclusion of jQuery, and using the syntax for a different version of PrimeFaces being most commonly among them.

I ran into a slightly different one though, when fighting to get a login screen to pop up on page load. I could see by checking PrimeFaces.widgets  that some widgets had been initialized, but my widget was not among them. I fought and argued and cried, but all in vain.

This error was breaking the rest of my JavaScript though, so I commented out the pop up and went to go work on something less frustrating.

Out of a cynical suspicion, I checked widgets again. Sure enough, there was my missing login dialog.

The Solution

It turns out that dialogs take a moment or two to get ready – this means that when a $(function() { } );  document ready call happens, the widgets might not be ready yet.

In my case I ended up moving my code to a

method, and now I have a hideous login screen popping up. But that’s a new problem.

The Neater Solutions

Shortly (very, actually) after this article was ‘twooted out, Çağatay Çivici was kind enough to respond to me. He mentioned that the safest way to get a hold of dialog widgets on page load would be to ensure that we placed the script tags just before the end body tag. Our options here are to either manually place the tag there, or use outputScript with target="body" . This ensures that our code runs last, at which time we can apparently rest assured that the widgets are ready.

Tagged with: , ,
Posted in Java

Leave a Reply