0

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="&lt;Select value&gt;" 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".

  • 1
    I haven't tried it, but `` has a `resetValues` attribute which should theoretically work (the same way as you intented to use ``). See also a.o. http://stackoverflow.com/questions/6642242/how-can-i-populate-a-text-field-using-primefaces-ajax-after-validation-errors-oc – BalusC Mar 16 '15 at 21:40
  • @BalusC: Thanks, I was aware of that, but I didn't find a way to combine all that into a working solution. The desired functionality being: _if_ there is an input validation failure on the input component **AND** the user entered a new value, the field should have the validation failure cleared and the new value should be validated. – Miha Vitorovič Mar 17 '15 at 06:55
  • Actually I just discovered that it works, with one exception: I was testing on the selectOneMenu, and before the validation error changing the value also triggers the _editing done_ action. **After** the validation error, the user has to specifically press _Enter_ even on the dropdown menu. – Miha Vitorovič Mar 17 '15 at 07:48

0 Answers0