Jsf Disable Inputbox With A Checkbox In A Ui:repeat On A Composite Component
Solution 1:
My
qty_#{qAndA.attribute.attribute_id}
is getting truncated toqty_
let alone all the other JSF ids prepended, which are because the composite component is a child of another composite component and both components are included conditionally using<ui:fragement>
No. It's because #{qAndA}
is only available during view render time instead of view build time. The <ui:repeat>
runs during view render time. If you had used <c:forEach>
, then it would have worked the way you expected. But, as indicated by your previous question, you could due to being restricted to old Mojarra 2.1.7 unfortunately not use JSTL to dynamically build the view the way you want.
But after all, you don't need to manually make the IDs dynamic like that. Just specify a fixed ID.
<h:inputText id="qty" ... />
The <ui:repeat>
will automatically prepend the iteration index in the ID. See also How to use EL with <ui:repeat var> in id attribute of a JSF component.
How can I reference an
<h:inputText>
from the<h:selectBooleanCheckbox>
which are in a<ui:repeat>
and part of acustomcomposite component so that I can disable and grey out an input box as depicted in the following screenshot
Just set the input's disabled
attribute to checkbox's value and use JSF-provided ajax facility to update the input when the checkbox is toggled:
<h:selectBooleanCheckboxvalue="#{qAndA.na_value}"><f:ajaxrender="qty" /></h:selectBooleanCheckbox>
...
<h:inputTextid="qty"value="#{qAndA.quantity}"disabled="#{qAndA.na_value}" />
No additional JS needed. For styling, just put this in a normal CSS file:
input[disabled] {
background-color: #808080;
}
Otherwise, if the input were initially disabled, and you re-enabled it using JavaScript without notifying JSF about this (via e.g. <f:ajax>
), then JSF would as part of safeguard against hacked requests still deny the submitted value. See also How to disable/enable JSF input field in JavaScript?
Unrelated to the concrete problem, you appear to want to render a HTML <table>
using <ui:repeat>
. Have you considered using <h:dataTable>
instead? It should reduce some HTML boilerplate. And, in that old Mojarra version, it has much more robust state saving while <ui:repeat>
is known to have bugs here and there in complex views with ajax stuff.
Solution 2:
The fix was to use p:dataTable
over the ui:repeat
...and use @form
on the ajax update. I feel since BalusC tipped me off on the ui:repeat
bug, I'll accept his answer as it was most helpful. But here is what worked
<composite:implementation><p:dataTableid="table"value="#{cc.attrs.checklist.answer_attribute_list}"var="qnA"><p:columnheaderText="NA"width="50px;"><p:selectBooleanCheckboxvalue="#{qnA.not_applicable}"><p:ajaxlistener="#{checklistEdit.checkBoxListenerTest}"update="@form" /></p:selectBooleanCheckbox><h:outputTextvalue="X"rendered="#{qnA.not_applicable}" /></p:column><p:columnheaderText="Quantity"width="75px;"><h:inputTextvalue="#{qnA.quantity}"id="qty"rendered="#{qnA.not_applicable == false}"size="1" /><h:outputTextvalue="#{qnA.quantity}"rendered="#{qnA.not_applicable == false}" /><h:outputTextvalue="-"rendered="#{qnA.not_applicable}" /></p:column></p:dataTable>
Post a Comment for "Jsf Disable Inputbox With A Checkbox In A Ui:repeat On A Composite Component"