XPage 自定义验证器 [英] XPages custom validator

查看:36
本文介绍了XPage 自定义验证器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最终我需要做一些跨领域验证,并认为我会使用自定义验证器来做到这一点.但我什至无法得到一个简单的例子.以下代码(与Mastering XPages"的第 116 页上的代码非常相似,允许任何值(包括空字段).我是否遗漏了一些明显的内容?

Ultimately I need to do some cross field validation and thought I would use a custom validator to do this. But I can't even get a simple example to work. The following code (which is pretty similar to that on p.116 of "Mastering XPages" allows any value (including an empty field). Am I missing something obvious?

            <xp:inputText
                id="field1"
                value="#{document1.field1}">
                <xp:this.validators>
                    <xp:customValidator>
                        <xp:this.validate><![CDATA[#{javascript:if (value == "") {
return new javax.faces.application.FacesMessage("Please enter a value");
}}]]></xp:this.validate>
                    </xp:customValidator>
                </xp:this.validators>
            </xp:inputText>

推荐答案

无法使用验证器验证空字段.验证器仅在值存在时运行.在 XPage 中,您有字段的 required 属性,它允许检查空字段;这是此问题的解决方法,并且(据我所知)无法创建自己的必需"验证器.

It is not possible to validate an empty field with a validator. A validator runs only if a value exist. In XPages you have the required property for fields which allows to check for empty fields; this is a workaround for this problem, and it is (as far as I know) not possible to create your own "required" validator.

如果您想创建自己的转换器,则必须创建一个转换器

If you want to create your own one, you have to create a converter instead

更新 21.06.2013

可以通过一个小的解决方法创建自己的必需验证器:http://hasselba.ch/blog/?p=764

It is possible to create an own required validator with a small workaround: http://hasselba.ch/blog/?p=764

这篇关于XPage 自定义验证器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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