Context
In a dialog a user can press a button to fill an existing datatable named qPdt. When he clicks on a row I want the row text to be inserted in some inputTextArea.
Problem
What happens is that if I open the dialog and click any row, everything works fine and as expected. But if I open the dialog and press the button, my script doesn't work anymore/isn't called anymore. I have to close the dialog and re-open it to make the script work.
Probably I'm lacking some javascript/jsf basics here. Any hint would be nice :)
Code
<script>
$('#accordion\\:duoDlgForm2\\:qPdt tr').on('click', function() {
var $item = $(this).closest("tr").find("td:nth-child(1)").text().trim();
$("#accordion\\:duoDlgForm2\\:rt1Selected").append($item);
});
</script>
Also tried (located inside the form and outside of it)
<script>
$(document).ready(function() {
$('#accordion\\:duoDlgForm2\\:qPdt').on('click','tr',function() {
var $item = $(this).closest("tr").find("td:nth-child(1)").text().trim();
$("#accordion\\:duoDlgForm2\\:rt1Selected").append($item);
});
});
</script>
datatable:
<p:scrollPanel mode="native">
<p:dataTable id="qPdt" var="p" value="#{regelBean.queriedParams}" scrollable="false"
emptyMessage="x" rowKey="#{p}" selection="" selectionMode="single">
<p:column>#{p.name}
<f:facet name="header" style="">Parameter</f:facet>
</p:column>
</p:dataTable>
</p:scrollPanel>
button to open the dialog
<p:commandButton id="selectButton" value="?" update=":stmtDetailForm :newDuoDlg" oncomplete="PF('newDuoDialog').show()" actionListener="#{regelBean.selectButtonHit(tVar)}">
button to populate the datatable
<p:commandButton value="<" update="qPdt regelDetail sp2" action="#{regelBean.findParams()}"/>
PF 4.0, IE9, working with includes.