How can I reference an <h:inputBox>
from the <h:selectBooleanCheckbox>
which are in a <ui:repeat>
and part of a composite component so that I can disable and grey out an input box as depicted in the following screenshot?
<ui:repeat var="qAndA" value="#{cc.attrs.checklist.answer_attribute_list}">
<td class="chklist"><h:selectBooleanCheckbox onclick="toggleBox(this, qty_#{qAndA.attribute.attribute_id})" value="#{qAndA.na_value}"> </h:selectBooleanCheckbox></td>
<td class="chklist"><h:inputText value="#{qAndA.quantity}" id="qty_#{qAndA.attribute.attribute_id}" /></td>
produces this HTML
<input id="j_idt48:2:j_idt94:j_idt94:j_idt167:j_idt171:1:qty_" type="text" name="j_idt48:2:j_idt94:j_idt94:j_idt167:j_idt171:1:qty_" value="6" />
My qty_#{qAndA.attribute.attribute_id}
is getting truncated to qty_
I tried
<h:selectBooleanCheckbox onclick="toggleBox(this, #{cc.attrs.id}_qty)" value="#{qAndA.na_value}"></h:selectBooleanCheckbox>
<h:inputText value="#{qAndA.quantity}" size="3" maxlength="3" id="#{cc.attrs.id}_qty"/>
I am trying to refactor this old jsp to JSF:
Original JSP Include:
<SCRIPT>
function toggleBox(checkName, quantityName) {
if(checkName.checked) {
quantityName.disabled=true;
quantityName.style.backgroundColor="#808080";
} else {
quantityName.disabled=false;
quantityName.style.backgroundColor="#FFFFFF";
}
}
</SCRIPT>
<c:forEach var="qAndA" items="${checklist.answer_attribute_list}">
<c:choose>
<c:when test="${empty qAndA.na_value || qAndA.na_value == '0'}">
<td class="chklist"><input type="checkbox" name="check_<c:out value="${qAndA.attribute_id}" />" onclick="toggleBox(this, qty_<c:out value="${qAndA.attribute_id}" />)" value="1"></td>
<td class="chklist"><input name="qty_<c:out value="${qAndA.attribute_id}" />" type="text" value="<c:out value="${qAndA.quantity}" />" ></td>
</c:when>
and produces this HTML
<td class="chklist"><input type="checkbox" name="check_1346788339807" onclick="toggleBox(this, qty_1346788339807)" value="1"></td>
<td class="chklist"><input name="qty_1346788339807" type="text" value="6" size="3" maxlength="3"></td>
Edit
quantity_checklist.xhtml composite component. the listener is called on the checklist.receiving_email
but not when it is part of the iteration, whether I use datatable or ui:repeat
<p:selectBooleanCheckbox value="#{cc.attrs.checklist.receiving_email}">
<p:ajax listener="#{checklistEdit.listenerTest()}" />
</p:selectBooleanCheckbox>
<h:dataTable var="qnA" value="#{cc.attrs.checklist.answer_attribute_list}">
<p:column>
<p:selectBooleanCheckbox value="#{qnA.na_value}">
<p:ajax render="qty" listener="#{checklistEdit.listenerTest}" update="@all"/>
</p:selectBooleanCheckbox>
</p:column>
<p:column>
<h:inputText value="#{qnA.quantity}" id="qty" disabled="#{qnA.na_value}" />
</p:column>
</h:dataTable>
EDIT 2
recap: trying to get a dynamic array of checkboxes to disable and gray out in input box using composites but no luck unless I move code out of composites. Here is the code using composites (related to How to refactor snippet of old JSP to some JSF equivalent?):
WorkItem.xhtml
<ui:repeat var="actionItem" value="#{workItemController.wfiwi.work_action_list}">
<ui:fragment rendered="#{actionItem.workActionClass.workActionType.action_type_id == '2'}">
<stk:dynamic_checklist actionItem="#{actionItem}" checklist="#{actionItem.meat}" />
</ui:fragment>
dynamic_checklist.xhtml composite
<ui:fragment rendered="#{cc.attrs.checklist.checkListClass.type == '3'}">
<stk:quantity_checklist actionItem="#{cc.attrs.actionItem}" checklist="#{cc.attrs.checklist}" />
</ui:fragment>
quantity_checklist.xhtml composite is shown above in my first Edit
If I move the quantity_checklist code up into the WorkItem.xhtml file, the ajax update works and the Qty inputbox is greyed out and disabled. But this won't work using composite components.
Edit 3
see code below...The ajax update on the receiving_email checkboxes properly affects id ddd
and poppy
but the qnA.na_value ajax update not so. In other words, I check the N/A checkbox next to Qty 6 in screenshot, the listener fires and the primefaces message I set in the listener is shown. But the input box is still active and not greyed out. However, if I then toggle the receiving_email checkbox, it's listener is fired, header message appear, AND the QTY box next to the 6 in the screenshot now goes gray and is disabled.
<h:panelGroup id="ccc">
<p:selectBooleanCheckbox value="#{cc.attrs.checklist.receiving_email}">
<p:ajax listener="#{checklistEdit.listenerTest()}" update="ddd,poppy" />
</p:selectBooleanCheckbox>
</h:panelGroup>
<h:panelGroup id="ddd">
<h:outputText value="Email Checkbox:"></h:outputText>
<h:outputText value="#{cc.attrs.checklist.receiving_email}" />
</h:panelGroup>
<h:dataTable var="qnA" value="#{cc.attrs.checklist.answer_attribute_list}" id="poppy">
<p:column headerText="NA">
<p:outputLabel id="navalue" value="#{qnA.na_value}"></p:outputLabel>
</p:column>
<p:column headerText="NA Checkbox">
<p:selectBooleanCheckbox value="#{qnA.na_value}">
<p:ajax listener="#{checklistEdit.checkBoxListenerTest}" update="poppy" />
</p:selectBooleanCheckbox>
</p:column>
<p:column headerText="Quantity">
<h:inputText value="#{qnA.quantity}" id="qty" disabled="#{qnA.na_value}" />
</p:column>
</h:dataTable>