Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wicket 错误消息中的变量_Wicket_Validation_Custom Validators - Fatal编程技术网

Wicket 错误消息中的变量

Wicket 错误消息中的变量,wicket,validation,custom-validators,Wicket,Validation,Custom Validators,我有一个下拉框和一个文本字段。根据所选内容,文本字段的值必须以唯一的数字开头。如果没有,将显示一条错误消息 根据选择,错误消息如下所示: 选择1时,“文本字段”中的数字必须以101开头 或 选择2时,“文本字段”中的数字必须以102开头 等等 我已经编写了一个自定义验证器来验证TextField 我不喜欢的是,对于每个错误,我都有一个资源键,它对应于错误消息的值: @Override protected void onValidate(IValidatable<String> val

我有一个下拉框和一个文本字段。根据所选内容,文本字段的值必须以唯一的数字开头。如果没有,将显示一条错误消息

根据选择,错误消息如下所示:

选择1时,“文本字段”中的数字必须以101开头

选择2时,“文本字段”中的数字必须以102开头

等等

我已经编写了一个自定义验证器来验证TextField

我不喜欢的是,对于每个错误,我都有一个资源键,它对应于错误消息的值:

@Override
protected void onValidate(IValidatable<String> validatable) {

    if(selection.equals(selections1) && !beginsWithGoodNumber){
        error(validatable, "error.selection1");
    }else if(selection.equals(selections1) && !beginsWithGoodNumber){
        error(validatable, "error.selection2");
    }else if(selection.equals(selections1) && !beginsWithGoodNumber){
        error(validatable, "error.selection3");
    }
}
我希望在属性文件中有类似的内容:

error.selection = the number in the '${label}' must begin with {number} for {selection}
其中
{number}
{selection}
是变量

这可能吗


谢谢。

您可能可以设置ValidationError对象并在validatable.error方法上进行设置。ValidationError有一个设置变量的方法。

假设您的验证器扩展了AbstractValidator,您可以将变量映射传递给#error()

或者参阅AbstractRangeValidator,了解如何创建ValidationError,在其上设置变量并将其报告给组件

error.selection = the number in the '${label}' must begin with {number} for {selection}