5

I am using primefaces 4.0 and jsf 2.2 in my Application. I have created a page where a datatable is nested in a tabview. Now when I want to filter the datatable, it keeps loading and doesn't how a result.

After some time i recognized, that javascript throws the following error: "Widget for var 'test' not available! ".

I guess this should be the issue, but what's the problem or how can i solve this? Does anyone have an idea?

Best Regards!

user3172567
  • 461
  • 1
  • 7
  • 19

3 Answers3

6

I am posting my answer here hopefully can help some people out there.

I have the same problem. My case is I want to perform the default filter for my <p:dataTable>, thus, I have to perform the PF('dtWidgetVar').filter(); script in javascript when page load.

This is my initial attemp:

$(document).ready(function() 
{
    PF('dtWidgetVar').filter();
});

It looks perfectly fine, but just doesn't work. Until I find the error in Chrome console Widget for var 'dtWidgetVar' not available!, and googling it for hours, finally I found this thread. Therefore I add a $(function(){}); to wrap my script as below:

$(document).ready(function() 
{
    $(function()
    {
        PF('dtWidgetVar').filter();
    });
});

BOOM!, finally it works. From here as well as here both stating that the $(function(){}); and $(document).ready(function(){}); are actually the same, so I have also no clue why it works. I have also try to only use $(function(){}); but it doesn't work. Have to use both functions to make it works, at least in my case. But still, I hope this helps some humans! Sorry for my bad English.

Newbie
  • 1,584
  • 9
  • 33
  • 72
  • 1
    Still helpful 2021 in my Environment Liferay 7.1, JSF 2.2 and PrimeFaces 7.0.14, also thank you for the links you have provided. – Gunnar Feb 23 '21 at 09:18
3

In the absence of posted code it's impossible to say. However, there are a couple of things I can suggest to look for.

  1. Check to see if you have a duplicate widget name in your view. Obviously you wouldn't intuit that from the message you got, but I recall in the past getting this same message for duplicate widget names
  2. Check to see if you have a component where you've given the widget var the same name as the ID. I've read that this is to be avoided.

  3. A very common error is to conflate ids and widget names. That is, you are trying to use an ID as a widget var

  4. See what in your code is trying to reference "test"

  5. I can't confirm this myself, but I've seen other StackOverflow posts that suggest this is a possible error when you have imported two copies of the jQuery library
DaBlick
  • 898
  • 9
  • 21
0

I've experienced Widget for var '[widgetVar]' not available when using p:ajax update="@all" inside a p:commandButton. I could avoid the issue by putting content to be updated in a h:panelGroup which I referenced in update and put the element declaring widgetVar outside that panel group.

Kalle Richter
  • 8,008
  • 26
  • 77
  • 177