0

在 wicket 应用程序中,我创建了自己的Validatorextends AbstractFormValidator,并且我有这样的代码:

StringBuilder errorMessage = new StringBuilder();
...
ValidationError valError = new ValidationError();
valError.addKey("error.close.date.period");
valError.setMessage(errorMessage.substring(1));
component1.error(valError);

但它只显示来自.properties文件的错误消息。如果我删除addKey("error.close.date.period")了行,那么它会显示来自errorMessageStringBuilder 的错误。我想显示两个错误。

4

1 回答 1

1

阅读ValidationError 的文档, setMessage 仅在未找到使用 addKey 添加的键时才提供回退。你不能同时拥有两者。您需要使用的是通过使用 setVariable(s) 进行变量替换,并使用属性文件中的变量键以及 addKey 添加的键下提供的错误消息,就像您已经做的那样。变量替换的工作方式类似于消息中的 ${variableKey}。

于 2014-11-22T16:32:40.093 回答