Since I started working with JSF pages, I struggled with CSS selectors. I thought that I understood the basic concept but turns out I must be missing something. Of course I read http://api.jquery.com/category/selectors/ but my impression is that these examples are too simple for my use case. So here is what I got in minimalistic form:
<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui">
<ui:define name="center">
<p:dialog header="Dialog" widgetVar="findParamDialog" resizable="false" id="findParamDlg" modal="true">
<h:form id="findParamForm">
<p:scrollPanel id="sp" mode="native">
<p:dataTable id="qPdt" var="p" value="..." rowKey="#{p}" selection=""
selectionMode="single">
<p:column>...</p:column>
</p:dataTable>
</p:scrollPanel>
<script>
$(document).ready(function() {
$('#sp').on('click','tr',function() {
var $item = $(this).closest("tr").find("td:nth-child(1)").text().trim();
alert('ye');
});
});
</script>
</h:form>
</p:dialog>
</ui:define>
When I click the row of my datatable I want the alert popup. On another xHTML page this is already working but the scenario is that there is no dialog that contains the scrollpanel.
Now, what I expect is that #sp refers to the one and only element with that id. But that's not working. Moreover, several tries to include the form (findParamForm\\:sp
or \\:findParamForm\\:sp
or #findParamForm\\:sp
or findParamForm sp
or findParamForm > sp
) didn't work either. So what is my thinking mistake here? Why can't I just refer to sp
with the id selector #
?
I have the impression is has something to do with these so-called container elements. Please tell me what I am missing here. I am 99,9% sure that the script itself is working, so I suspect the selector. Thanks in advance