Note that there are some explanatory texts on larger screens.

plurals
  1. POUse jQuery to sync values of Primefaces JSF2 components (inputText)
    text
    copied!<p>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:</p> <p><strong>template.xhtml</strong></p> <pre><code>&lt;h:head&gt; &lt;script src="#{request.contextPath}/js/my.js" type="text/javascript"&gt;&lt;/script&gt; &lt;/h:head&gt; &lt;h:body&gt; &lt;h:form id="main_form"&gt; &lt;ui:insert name="content"/&gt; &lt;/h:form&gt; &lt;/h:body&gt; </code></pre> <p><strong>myview.xhtml</strong></p> <pre><code>&lt;ui:composition ... template="templates.xhtml"&gt; &lt;ui:define name="content"&gt; &lt;p:inputText id="title1" value="#{myBean.title1}" /&gt; &lt;p:inputText id="title2" value="#{myBean.title2}" /&gt; &lt;p:commandLink id="syncBtn" styleClass="ui-icon ui-icon-arrowthick-1-e" /&gt; &lt;/ui:define&gt; </code></pre> <p><strong>my.js</strong></p> <pre><code>$('#main_form\\:syncBtn').click(function() { $('#title2').val($('#title1').val()); }); </code></pre> <p>The jQuery scripts/functions are not attached to the elements</p> <p>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.</p> <p><strong>EDIT</strong>: 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.</p> <pre><code>$('[id="main_form:syncBtn"]').click(function() { alert("Test"); }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload