OmniFaces o:validateAllOrNone in ui:repeat or h:dataTable

前端 未结 1 1808
臣服心动
臣服心动 2021-01-21 11:34

Is it possible to use OmniFaces (which is pretty cool ;)) within an or ?<

相关标签:
1条回答
  • 2021-01-21 12:08

    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.

    0 讨论(0)
提交回复
热议问题