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

怎甘沉沦 提交于 2019-12-20 03:17:16

问题


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:


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.



来源:https://stackoverflow.com/questions/16776668/omnifaces-ovalidateallornone-in-uirepeat-or-hdatatable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!