1

I have an h:dataTable inside of an h:form, where each row has it's own h:commandButton type="submit" action="#{bean.saveChanges(item)}".

f:inputs are declared as required and they also need to match a pattern.

If every input is in the right format, then it works fine.

Otherwise it needs only one input to be wrong and an updating function on a commandButton corresponding to a completely different item in another row seems not to be called, therefore not updated in the database.

Also only the wrong row's validation message is displayed and the changes are maintained in the view by a (backing Spring view scoped) bean, so the user might actually think, that the initial row was indeed updated in the database too.

Is there a way, how to separate individual rows of the h:dataTable, so that the validation messages of another row does not stop other items from being updated by the method of a (Spring/backing) bean?

Kit Ostrihon
  • 824
  • 2
  • 14
  • 36

2 Answers2

2

Use ajax to process/execute only the current row. You can achieve that by explicitly specifying the client IDs of the input components in <f:ajax execute>.

<h:form>
    <h:dataTable ...>
        <h:column>
            <h:inputText id="foo" ... />
        </h:column>
        <h:column>
            <h:inputText id="bar" ... />
        </h:column>
        <h:column>
            <h:inputText id="baz" ... />
        </h:column>
        <h:column>
            <h:commandButton ...>
                <f:ajax execute="foo bar baz @this" ... />
            </h:commandButton>
        </h:column>
    </h:dataTable>
</h:form>

This won't process the inputs in other rows. Use if necessary <f:ajax render> to update the <h:message(s)> associated with the inputs.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thank you very much. If I am using `f:passThroughAttribute`s with `setCustomValidity` on the `h:inputText`s, is there a way how to re-render the generated HTML5 error messages texts too? I have tried setting the `render` attribute to the whole `@form`, adding `f:passThroughAttribute` and/or the inputs ids, it seems to have the actions set on the inputs and marked *red* as invalid, but the *bubble* message is not shown after clicking the `h:commandButton` like it was without the `f:ajax`. Is it a matter of a processing order? Can it be forced to show by some `f:ajax` attribute's value? – Kit Ostrihon Apr 08 '16 at 10:57
  • 1
    You're welcome. Sorry, no clue what you mean with "the generated HTML5 error messages texts". This doesn't seem to be JSF-related and thus also not JSF's responsibility. At least, doing `render="@form"` will cause all non-saved input fields to get lost. You really don't want to unnecessarily render/update parts which aren't changed at all. Render/update only the components representing the messages. See also the "See also" link for an in depth elaboration of how most efficiently use those execute/render attributes. – BalusC Apr 08 '16 at 11:01
-2

The required on the input cause the Process validation to fail and the render response to be invoked.

A simple solution could be You could remove the required from the input and handle the case in you managed bean. Since the action would move on till Phase 5: Invoke application the valid data can be saved. For all invalid rows highlight the row by having a boolean in you data model.

Ravi
  • 391
  • 2
  • 18