OmniFaces validateOrder禁用 [英] OmniFaces validateOrder disabling

查看:91
本文介绍了OmniFaces validateOrder禁用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用validateOrder组件来验证两个java.util.Date对象。它类似于展示示例此链接(PrimeFaces示例)。一切都很完美,但我有一个问题:

I'm trying to use validateOrder component to validate two java.util.Date objects. It is similar to showcase example on this link (PrimeFaces example). Everything works perfect, but i have one question:

如果不需要第二个日期字段怎么办?

What if 2nd date field is not required?

在这种情况下,我得到了nullpointer异常,并且由于validateOrder具有禁用属性,我想知道是否值得/可能每次都通过ajax启用/禁用它插入/删除第二个日期。如果没有,我想我会坚持使用Balus的JSF2.0交叉字段验证方法你可以在这个链接上阅读

In that case i'm getting nullpointer exception, and since validateOrder has "disabled" attribute, i was wondering is it worth/possible enabling/disabling it via ajax every time the 2nd date is inserted/removed. If not, i guess i'll stick to Balus' approach for JSF2.0 cross-field validation that you can read about on this link.

推荐答案

禁用属性检查是否填写了第二个字段。如果未填写,则与字段的客户端ID关联的请求参数值将为空。使用exaclty让禁用属性评估为 true

Let the disabled attribute check if the 2nd field is filled in. If it's not filled in, the request parameter value associated with field's client ID will be empty. Use exaclty that to let disabled attribute evaluate to true.

<p:calendar ... binding="#{endDate}" />
...
<o:validateOrder ... disabled="#{empty param[endDate.clientId]}" />

代码按原样。绑定不需要额外的支持bean属性。

Code is as-is. No additional backing bean property necessary for binding.


  • < a href =https://stackoverflow.com/questions/14911158/how-binding-attribute-in-jsf-works>绑定属性如何在JSF中起作用?何时以及如何使用?

  • How does the 'binding' attribute work in JSF? When and how should it be used?

这篇关于OmniFaces validateOrder禁用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆