I have a dataTable with cell editor. And I want to only have some (selected) rows editable. And when the user uses the cell editor, I want to perform input validation immediately after the value is set.
So I use cellEdit event in the data table and from the event handler I trigger validation failure.
<p:ajax event="cellEdit" listener="#{bean.onEditCell}" update=":formId:propertySelect" />
This works like a charm. If the user enters an invalid value, the editor doesn't close and the error message is displayed.
What doesn't work is the user inputting a valid value afterwards. The cellEdit event does not trigger again since the form is in "input validation failure state".
I have lost a day trying to resolve that:
- I want to reset input validation when a user sets a new value - resetInput only works from buttons. I couldn't get it working on value change.
- I didn't find how to reset the field from JavaScript directly.
if I combine "onchange" event and "remoteCommand" a handler is called in the backing bean, but then I cannot find the UIInput to call resetValue() on it.
<p:dataTable id="propertySelect" value="#{bean.propertyValues}" var="prop" editable="true" editMode="cell" scrollable="true" scrollHeight="200" widgetVar="propSelectTable" filteredValue="#{bean.filteredPVs}"> <p:ajax event="cellEdit" listener="#{bean.onEditCell}" update=":#{formId}:propertySelect" /> <p:ajax event="filter" oncomplete="updateToggle()" /> <p:column id="rowSelection"> <f:facet name="header"> <p:selectBooleanCheckbox id="toggleAll" value="#{bean.selectAllRows}"> <p:ajax listener="#{bean.handleToggleAll}" update=":#{formId}:propertySelect" /> </p:selectBooleanCheckbox> </f:facet> <p:selectBooleanCheckbox value="#{prop.selected}"> <p:ajax update=":#{formId}:propertySelect" oncomplete="updateToggle()" listener="#{bean.rowSelectListener(prop)}"/> </p:selectBooleanCheckbox> </p:column> <p:column headerText="Property"> <h:outputText value="#{prop.name}" /> </p:column> <p:column headerText="Description"> <h:outputText value="#{prop.description}" /> </p:column> <p:column headerText="Value"> <p:cellEditor rendered="#{prop.selected}"> <f:facet name="output"> <h:outputText value="#{bean.displayPV(prop)}" /> </f:facet> <f:facet name="input"> <p:inputText id="pvSimple" value="#{prop.uiValue}" rendered="#{prop.propertyValueUIElement eq 'INPUT'}" /> <p:inputTextarea id="pvArea" rows="7" value="#{prop.uiValue}" rendered="#{prop.propertyValueUIElement eq 'TEXT_AREA'}" /> <p:selectOneMenu id="pvEnum" value="#{prop.uiValue}" rendered="#{prop.propertyValueUIElement eq 'SELECT_ONE_MENU'}"> <f:selectItem itemLabel="<Select value>" itemValue="" /> <f:selectItems value="#{prop.enumOptions}" var="enum" itemLabel="#{enum}" itemValue="#{enum}" /> </p:selectOneMenu> </f:facet> </p:cellEditor> <h:outputText value="-" rendered="#{!prop.selected}" /> </p:column>
I am looking for a way to clear input validation errors on the input fields with the ids "pvSimple", "pvArea" or "pvEnum".