Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Primefaces - Datatable Widget for var ... not available

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!

like image 763
user3172567 Avatar asked Apr 08 '14 06:04

user3172567


2 Answers

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.

like image 144
Newbie Avatar answered Sep 24 '22 08:09

Newbie


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
like image 33
DaBlick Avatar answered Sep 24 '22 08:09

DaBlick