OmniFaces o:在ui中的validateAllOrNone:repeat或h:dataTable [英] OmniFaces o:validateAllOrNone in ui:repeat or h:dataTable
问题描述
可以在< ui:repeat>之内使用OmniFaces
或< o:validateAllOrNone>
(这是非常酷的)) < h:dataTable>
?
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.
如果我将< o:validateAllOrNone>
在< ui:repeat>
或< h:dataTable>
中,并使用输入的ID在组件
属性中,如果所有字段都为空,则验证器也会被触发。
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.
推荐答案
不,这是不可能的。 组件
属性必须在物理上引用多个组件,而不是单个渲染多个组件。然而,它可以用于在相同迭代期间呈现的物理多个组件。多重验证器不是为了引用多次渲染的单个组件而设计的,< o:validateXxx>
唯一的OmniFaces验证器是< o:validateUniqueColumn>
。
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>
.
如果要使用< o:validateXxx>
基于集合的动态输入的多字段验证器,那么你最好的选择是使用JSTL < c:forEach> / code>。它将构建多个组件。
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.
例如
<c:forEach items="#{bean.items}" var="item" varStatus="loop">
<h:inputText id="input_#{loop.index}" value="#{item.value}" />
</c:forEach>
假设有3个项目,这将动态创建ID为$ code的JSF组件> input_0 , input_1
和 input_2
。那么你可以使用< o:validateXxx>
如下(将其放在循环之外!)
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" />
您可以通过EL表达式替换上述示例中的硬编码字符串,返回所需的空格分隔字符串来自支持bean的组件ID。
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}" />
另一种方法是创建一个< x:validateAllOrNoneColumn>
或在OmniFaces问题跟踪器上发布增强请求。更改现有的< o:validateAllOrNone>
这是一个完全独立的组件,这不是很简单。
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.
这篇关于OmniFaces o:在ui中的validateAllOrNone:repeat或h:dataTable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!