我正在使用Oval http://oval.sourceforge.net/进行java bean验证,并且在使用表达式语言功能时遇到异常。
我的代码如下所示:
@NotNull(errorCode = "paymentCard.number.invalid", message = "Required", when = "_this.cardType != null")
private String cardNumber;
结果是
WARNING: Cannot determine constraint when formula based on annotation $Proxy10
java.lang.ArrayIndexOutOfBoundsException: 1
at net.sf.oval.AbstractCheck.setWhen(AbstractCheck.java:276)
at net.sf.oval.configuration.annotation.AbstractAnnotationCheck.configure(AbstractAnnotationCheck.java:183)
at net.sf.oval.configuration.annotation.AnnotationsConfigurer.initializeCheck(AnnotationsConfigurer.java:323)
at net.sf.oval.configuration.annotation.AnnotationsConfigurer.configureFieldChecks(AnnotationsConfigurer.java:143)
at net.sf.oval.configuration.annotation.AnnotationsConfigurer.getClassConfiguration(AnnotationsConfigurer.java:294)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
31-Jul-2013 18:04:51 net.sf.oval.internal.Log info
INFO: Available ScriptEngine language names: [[js, rhino, JavaScript, javascript, ECMAScript, ecmascript]]
我不知道为什么会这样,有人可以帮帮我吗?
提前致谢
答案 0 :(得分:1)
您必须首先编写前缀以指示实现使用的Oval,但是还需要注册要在项目中使用的表达式语言实现。如果没有这个步骤,Oval将无法确定您用于解析EL表达式的实现。
private static final Validator VALIDATOR = new Validator();
static {
VALIDATOR.getExpressionLanguageRegistry().registerExpressionLanguage("js",
new ExpressionLanguageJavaScriptImpl());
}
答案 1 :(得分:0)
您需要在公式前加上语言ID,例如
when="js:_this.cardType != null"