我正在使用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]]
我不知道为什么会这样,有人可以帮助我吗?
提前致谢
最佳答案
您必须首先编写前缀以指示Oval哪个实现使用,但是还必须注册要在项目中使用的Expression Language实现。没有此步骤,Oval将无法弄清楚您正在使用哪种实现来解析您的EL表达式。
private static final Validator VALIDATOR = new Validator();
static {
VALIDATOR.getExpressionLanguageRegistry().registerExpressionLanguage("js",
new ExpressionLanguageJavaScriptImpl());
}