validation - 输入字段按什么顺序进行验证?

标签 validation jsf

在 JSF 验证阶段,输入字段按什么顺序进行验证?

我对尝试的想法如下:我有一组可能通过或失败转换/验证的输入字段。另外,我希望使用自定义验证器进行一些输入,该验证器会根据所有其他字段是否通过验证而产生不同的结果。我可以检查 FacesContext 中是否有任何先前的消息,但我必须确保在检查了所有其他字段之后调用此自定义转换器,因此出现了上述问题。这只是它们在 Facelets-Page 中定义的顺序吗?如果是这样,这个订单能得到保证吗?

最佳答案

Is it simply the order in which they are defined in the Facelets-Page?

基本上是的。组件树将以“通常的方式”递归处理。对于每个组件,首先将处理组件本身,然后按顺序处理其每个子组件。


If so, would this order be guaranteed?

是的。 JSF 2.0 specification 中对此进行了说明。 :

2.2.3 Process Validations

...

During the Process Validations phase of the request processing lifecycle, the JSF implementation must call the processValidators() method of the UIViewRoot of the tree. This will normally cause the processValidators() method of each component in the tree to be called recursively, as described in the API reference for the UIComponent.processValidators() method.

...

因此,自定义转换器应由最后一个组件或“ stub ”<h:inputHidden> 引用。组件位于所有所需组件之后。所需的组件可以通过组件绑定(bind)传递。另请参阅此相关答案:JSF doesn't support cross-field validation, is there a workaround?

作为完全不同的替代方案,您可以考虑将整个内容包装在复合 Material 中。

关于validation - 输入字段按什么顺序进行验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12933982/

相关文章:

C# .net Core Fluentvalidation 手动验证获取验证器类实例

java - 如何验证此 Java 代码的用户输入?

java - java中获取#后面的url参数

java - Icefaces 1.8 外观和感觉问题

jsf - 当使用惰性数据表时,另一个组件无法更新/第二个组件数据落后于一个请求

jsf - CDI 托管 Bean 和 JSF 托管 Bean 可以相互通信吗?

javascript - 如何在 JSF 页面的 JavaScript 函数中使用小于或大于符号?

c# - View中动态添加 "data-val"和 "data-val-required"是不是有问题?

python - 如何对 Flask-admin 字段执行验证

python - 简单的Python输入错误