2
votes

Is it possible to use OmniFaces <o:validateAllOrNone> (which is pretty cool ;)) within an <ui:repeat> or <h:dataTable>?

I need a table with each row having an input field column. You could either fill in none of these values or all of them.

If I put the <o:validateAllOrNone> within the <ui:repeat> or <h:dataTable> and use the id of the input field in components attribute, then the validator also gets triggered, if all fields are empty.

1

1 Answers

1
votes

No, that's not possible. The components attribute must refer physically multiple components, not a single component which is rendered multiple times. It can however be used on physically multiple components which are rendered during same iteration round. The <o:validateXxx> multi field validator is not designed to reference a single component which is rendered multiple times. The only OmniFaces validator which does that is <o:validateUniqueColumn>.

If you want to use the <o:validateXxx> multi field validator on dynamic inputs based on a collection, then your best bet is to use JSTL <c:forEach>. It will build physically multiple components.

E.g.

<c:forEach items="#{bean.items}" var="item" varStatus="loop">
    <h:inputText id="input_#{loop.index}" value="#{item.value}" />
</c:forEach>

Assuming that there are 3 items, this will dynamically create JSF components with IDs of input_0, input_1 and input_2. Then you can just use <o:validateXxx> as follows (put it outside the loop!)

<o:validateAllOrNone components="input_0 input_1 input_2" />

You can replace the hardcoded string in the above example by an EL expression which returns the desired space separated string of component IDs from a backing bean.

<o:validateAllOrNone components="#{bean.inputIds}" />

An alternative would be to create a <x:validateAllOrNoneColumn> yourself or to post an enhancement request at OmniFaces issue tracker. It would be not exactly trivial to alter the existing <o:validateAllOrNone> that a completely separate component is desired.