Search code examples
jqueryjsf-2jquery-selectorsprimefacesmanaged-bean

cannot accept jquery selector from managed bean jsf2 primefaces


I want to execute jquery from managed bean but I have this problem wtih selector :

Uncaught Error: Syntax error, unrecognized expression: unsupported pseudo: lesarticles 

here is the managed bean code :

RequestContext.getCurrentInstance().execute("$('#tabView\\:lesarticles').children().find('table tbody tr td div').css('display', 'none');");

and here is the tree of components

<p:tabView id="tabView">
<p:tab>
<p:datatable id="lesarticles">......

and when I run :

RequestContext.getCurrentInstance().execute("$('#tabView:lesarticles').children().find('table tbody tr td div').css('display', 'none');");

I have also error

how can I resolve that

thank you


Solution

  • In order to minimize the escaping issues just do

    RequestContext.getCurrentInstance().execute("easyNameFunc();");
    

    and in your js create

    function easyNameFunc(){
        $('#tabView\\:lesarticles').children().find('table tbody tr td div').css('display', 'none');
    }
    

    That way you can do a better debugging and have less pitfalls