This discussion is archived
6 Replies Latest reply: Dec 14, 2012 11:57 AM by SrinivasJilla RSS

referencing <af:selectManyCheckbox> w/ adf.PAGE.findComponentByAbsoluteId()

979859 Newbie
Currently Being Moderated
I've been getting a null error when using adf.page.findComponentByAbsoluteId(). At first i was using document.getElementsByName(*direct DOM name in here*) but of course while it worked locally it wasn't working on other servers so I've been trying to get the AdfPage.PAGE.findComponentByAbsoluteId() to work. This is for my job so I can't post the complete code but I'll post what is necessary to understand what is going on. It's a .jsff so there is no af:document tag.

I would like to access the below component as an array of checkboxes so I can go through it and perform some validation: disable the unchecked boxes if the number of checked boxes is above a constant, 7, but re-enable them if it goes below 7. I've been forced to use javascript because I don't see a way to see if an individual check box is checked or not. The number of checkboxes is allocated dynamically based on how many beneficiaries there are.

<af:selectManyCheckbox id="letterSelectMany" value="#{giqdBackingBean.selectedBeneficiariesForPdf}"
autoSubmit="true" clientComponent="true">

<af:forEach var="bene" items="#{giqdBackingBean.eligibleBeneficiaries}">
<af:selectItem id="letterBeneSelect" label="#{bene.firstLastName} (#{bene.associationReason})" value="#{bene}"/>
</af:forEach> />

Here is the javascript:

<af:resource type="javascript">
window.setTimeout(init,3000); // i was having trouble with onload for some reason but this seems to work for the moment
function init() {
var boxes=document.getElementById(AdfPage.PAGE.findComponentByAbsoluteId('letterSelectMany').getClientId()); // this results in a null currently


for (var i=0;i < boxes.length;i++) {
if(boxes.addEventListener) {
boxes.addEventListener("click",checkBoxValidator,false); // one of these is for older versions of IE and the other is for other chrome/mozilla etc. but i forget which is which
}
else if (boxes.attachEvent) {
boxes.attachEvent("onclick", checkBoxValidator);
}
}
}

function checkBoxValidator() {
var boxes=document.getElementById(AdfPage.PAGE.findComponentByAbsoluteId('letterSelectMany').getClientId());

var checkedBoxes = 0;
for (var i=0;i < boxes.length;i++) {
if(boxes.tagName == "INPUT" && boxes.checked) {
checkedBoxes++;
}
}
if(checkedBoxes >= 7) {
for (var j=0;j < boxes.length;j++) {
if(boxes[j].tagName == "INPUT" && ! boxes[j].checked) {
boxes[j].disabled = true;
}
}
}
else {
for (var k=0;k < boxes.length;k++) {
if(boxes[k].tagName == "INPUT" && ! boxes[k].checked) {
boxes[k].disabled = false;
}
}
}
}
</af:resource>

So there you have it. Pretty simple stuff but I've been struggling to get it to reference the checkbox component in javascript. I had been using, var boxes= document.getElementsByName("r1:0:letterSelectMany"); , which worked just fine on my server but it doesn't work on other servers. Thanks for any input.

PS: I had initially replied to relevant thread but I thought it was more appropriate and hopefully will get more attention as its own thread.

Edited by: 976856 on Dec 13, 2012 2:45 PM

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points