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

  • SEARCH
  • Home
  • 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 8151257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:19:25+00:00 2026-06-06T15:19:25+00:00

i want to use jQuery to sync values of JSF2 components. We are using

  • 0

i want to use jQuery to sync values of JSF2 components.
We are using templates. As i am not sure if this may be a cause why the below script is not working, i will show you the code design:

template.xhtml

<h:head>
    <script src="#{request.contextPath}/js/my.js" type="text/javascript"></script>
</h:head>
<h:body>
    <h:form id="main_form">
        <ui:insert name="content"/>
    </h:form>
</h:body>

myview.xhtml

<ui:composition ... template="templates.xhtml">
<ui:define name="content">
    <p:inputText id="title1" value="#{myBean.title1}" />    
    <p:inputText id="title2" value="#{myBean.title2}" />
    <p:commandLink id="syncBtn" styleClass="ui-icon ui-icon-arrowthick-1-e" />
</ui:define>

my.js

$('#main_form\\:syncBtn').click(function() {
    $('#title2').val($('#title1').val());
});

The jQuery scripts/functions are not attached to the elements

I know i can use callbacks (onblur, onclick, etc), but i want to avoid this because and use a more generic solution because i have a lot of those input fields.

EDIT:
i tried BalusC answer (which is of course correct), but there must be another error. because it did not work. I inserted an js alert, but it´s not being dispayed.

$('[id="main_form:syncBtn"]').click(function() {
    alert("Test");
});
  • 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-06-06T15:19:27+00:00Added an answer on June 6, 2026 at 3:19 pm

    That’s because they don’t have a client ID of title1 and title2, so jQuery can’t find them. They have instead an ID of main_form:title1 and main_form:title2. Fix your JS code accordingly.

    $('#main_form\\:syncBtn').click(function() {
        $('#main_form\\:title2').val($('#main_form\\:title1').val());
    });
    

    For starters who haven’t memorized how exactly JSF generates HTML, you should ignore the JSF source code when writing jQuery code and instead look at the JSF-generated HTML code. You can do that in the webbrowser by rightclick and View Source or using the "Inspect Element" feature of the webbrowser’s web developer toolset.

    See also:

    • How to select JSF components using jQuery?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use jquery delegate to call a function, and this works fine:
i want to use jquery ui auto complete plugin in asp.net. this is my
I want to use jquery to build HTML like this: <li><a href=#><span class=play></span><span class=trackName>Track
I want to use jQuery to parse RSS feeds. Can this be done with
I want to use jquery's (.load) function in CI, should i place this jquery
I want to use jQuery UI's autocomplete as a combobox, as showed in this
I already started this in javascript so I don't want to use jquery but
First off: I do not want to use JQuery, i know it would make
I want to use jQuery to delete cookies; I have tried this: $.cookie('name', '',
I want to use jquery autocomplete in a foreach loop. When using ids, only

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.