Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6745779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:14:42+00:00 2026-05-26T12:14:42+00:00

I am trying to implement jQuery with PrimeFaces and JSF components, but it’s not

  • 0

I am trying to implement jQuery with PrimeFaces and JSF components, but it’s not working properly. When I tried to do the same with HTML tags it;s working properly.

Here is the code with HTML tags which works properly with jQuery:

<input type="checkbox" id="check2"></input>
<h:outputText value="Check the box, if your permanent address is as same as current address."></h:outputText> 
<h:message for="checkbox" style="color:red" />

with

$("#check2").change(function() {
    if ($("#check2").is(":checked")) {
        $("#p2").hide();
    } else {
        $("#p2").show();
    }
});

Here is the code with PrimeFaces/JSF which doesn’t work properly with jQuery:

<p:selectManyCheckbox >
    <f:selectItem itemLabel="1" value="one" id="rad" ></f:selectItem>
</p:selectManyCheckbox>

with

$("#rad").change(function() {
    if ($("#rad:checked").val() == "one") {
        $("#p2").hide();
    } else {
        $("#p2").show();
    }  
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:14:43+00:00Added an answer on May 26, 2026 at 12:14 pm

    You should realize that jQuery works with the HTML DOM tree in the client side. jQuery doesn’t work directly on JSF components as you’ve written in the JSF source code, but jQuery works directly with the HTML DOM tree which is generated by those JSF components. You need to open the page in webbrowser and rightclick and then View Source. You’ll see that JSF prepends the ID of the generated HTML input elements with the IDs of all parent NamingContainer components (such as <h:form>, <h:dataTable>, etc) with : as default separator character. So for example

    <h:form id="foo">
        <p:selectManyCheckbox id="bar" />
        ...
    

    will end up in generated HTML as

    <form id="foo" name="foo">
        <input type="checkbox" id="foo:bar" name="foo:bar" />
        ...
    

    You need to select elements by exactly that ID instead. The : is however a special character in CSS identifiers representing a pseudo selector. To select an element with a : in the ID using CSS selectors in jQuery, you need to either escape it by backslash or to use the [id=...] attribute selector or just use the old getElementById():

    var $element1 = $("#foo\\:bar");
    // or
    var $element2 = $("[id='foo:bar']");
    // or
    var $element3 = $(document.getElementById("foo:bar"));
    

    If you see an autogenerated j_idXXX part in the ID where XXX represents an incremental number, then you must give the particular component a fixed ID, because the incremental number is dynamic and is subject to changes depending on component’s physical position in the tree.


    As an alternative, you can also just use a class name:

    <x:someInputComponent styleClass="someClassName" />
    

    which ends up in HTML as

    <input type="..." class="someClassName" />
    

    so that you can get it as

    var $elements = $(".someClassName");
    

    This allows for better abstraction and reusability. Surely those kind of elements are not unique. Only the main layout elements like header, menu, content and footer are really unique, but they are in turn usually not in a NamingContainer already.


    As again another alternative, you could just pass the HTML DOM element itself into the function:

    <x:someComponent onclick="someFunction(this)" />
    
    function someFunction(element) {
        var $element = $(element);
        // ...
    }
    

    See also:

    • How can I know the id of a JSF component so I can use in Javascript
    • How to use JSF generated HTML element ID with colon ":" in CSS selectors?
    • By default, JSF generates unusable IDs, which are incompatible with the CSS part of web standards
    • Integrate JavaScript in JSF composite component, the clean way
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement the Jquery datepicker using a google hosted theme. But
I'm trying to implement the awesome Dropkick jQuery plugin , but for some reason
I'm working on a mobile view of our site. I'm trying to implement JQuery
I'm trying to implement back button on this full ajax website.. I tried jquery
i am trying to implement jquery datatable , in my cakePHP based website, but
I've been trying to implement the jquery.safetynet plug-in but I've been having difficulties getting
I've been trying to implement snook.ca's Simplest jQuery Slideshow, but when applied to child
since Google translate api will stop working i'm trying to implement some jquery code
I am trying to implement struts2-jquery-grid. But I am stuck with the serialization issue.
I am trying to implement this jQuery auto complete function but the problem is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.