I need to display a table of rows with each row having an anchor which on clicking opens a dialog (div content) based on the anchor tag clicked. As these anchors are generated dynamically, I need to find a way of identifying the anchor tag that was clicked and open up the corresponding dialog.
XHTML code below:
<ui:repeat var="vDetailTO" value="#{vAdmBean.displayVDetailTOList}" varStatus="vCounter">
<tr>
<td align="left">
<h:outputText value="#{vDetailTO.userId}" />
</td>
<td align="left">
<a id="dialogLink-#{vCounter.index}" href="#" owNumber="#vendorCounter.index}">+</a>
<div id="aNodeSearch-popupLink-#{vCounter.index}" title="Node"
style="display:none;">
The content is actually big. So, just typing this text here.
Note that this is the div tag that needs to open based on the anchor tag clicked
as the content varies for each anchor tag
</div>
</tr>
</ui:repeat>
JS Code
$("#aNodeSearch-popupLink-"+$("#frmNode\\:hdnRecordIndex").val()).click(function() {
var rowNumber = $(this).attr('rowNumber');
$("#frmNode\\:hdnRecordIndex").attr("value", rowNumber);
$("#aNodeSearch-popup-"+rowNumber).dialog("open");
});
$("#aNodeSearch-popup-"+$("#frmNode\\:hdnRecordIndex").val()).dialog(
{
autoOpen : false,
modal : false,
resizable : false,
height : 500,
width : 750,
buttons : {
"Submit" : function() {
var selNodes = "";
var rowNumber = $("#frmNode\\:hdnRecordIndex").val();
var availNodes = "aNodeAvailListId-" + rowNumber;
$('#' + availNodes + ' input:checkbox:checked').each(
function() {
selNodes += $(this).val() + ",";
});
$("#frmNode\\:hdnArticleNodeIds").attr("value",
selNodes);
frmNode["frmNode:btnRefresh"]
.click();
$(this).dialog("close");
}
}
});
When the anchor in the first row is clicked, the dialog opens fine and am able to do the needful. However, when I click the subsequent row, there is nothing that happens and even Firefox web console does not show a problem. But if I hardcode the code in js with
aNodeSearch-popupLink-1.click and
aNodeSearch-popupLink-2.click and so on as shown below..
am able to view the dialog boxes as required.
$("#aNodeSearch-popupLink-1").click(function() {
$("#aNodeSearch-popup-1").dialog("open");
});
$("#aNodeSearch-popup-1").dialog(
{
........
});
Any ideas on how I can handle this scenario of identifying the clicked anchor tag and open their corresponding dialogs ?