在 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 theUIViewRoot
of the tree. This will normally cause theprocessValidators()
method of each component in the tree to be called recursively, as described in the API reference for theUIComponent.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/