Wicket 如何从Select中删除验证程序?
我有一个表单,需要在其中动态添加/删除验证器。根据下拉选择,其他表单字段可能具有不同的验证规则 对于其他类型的输入,我使用了Wicket 如何从Select中删除验证程序?,wicket,validation,Wicket,Validation,我有一个表单,需要在其中动态添加/删除验证器。根据下拉选择,其他表单字段可能具有不同的验证规则 对于其他类型的输入,我使用了replace(methodthattreatesInput())来摆脱以前添加的验证器。(不知道更好的方法。特别是,似乎没有任何方法可以直接从组件中删除验证器…) 使用wicket extensions的,这种方法失败的原因如下: WicketMessage: submitted http post value [[Ljava.lang.String;@5b4bf56d]
replace(methodthattreatesInput())
来摆脱以前添加的验证器。(不知道更好的方法。特别是,似乎没有任何方法可以直接从组件中删除验证器…)
使用wicket extensions的,这种方法失败的原因如下:
WicketMessage: submitted http post value [[Ljava.lang.String;@5b4bf56d]
for SelectOption component [8:myForm:targetInput] contains an
illegal relative path element [targetConsortiums:1:option] which does not
point to an SelectOption component. Due to this the Select component cannot
resolve the selected SelectOption component pointed to by the illegal value.
A possible reason is that component hierarchy changed between rendering and
form submission.
创建选择的方法:
private FormComponent<?> targetSelection() {
Map<Class<? extends Target>, List<Target>> targets = targetService.getAllAsMap();
SelectOptions<Target> propertyOptions = new SelectOptions<Target>("targetConsortiums",
targets.get(Consortium.class), new TargetRenderer());
SelectOptions<Target> consortiumOptions = new SelectOptions<Target>("targetProperties",
targets.get(Property.class), new TargetRenderer());
Select select = new Select(ID_TARGET, new PropertyModel<Target>(model, "target"));
select.add(propertyOptions);
select.add(consortiumOptions);
select.setRequired(true);
select.setMarkupId(ID_TARGET);
return select;
}
private FormComponent targetSelection(){
Map我不知道如何在Wicket 1.4上实现这一点,但在Wicket 1.5上,FormComponent上的验证器有一个删除方法(请参见)我想出了一个相对简单的解决方法:使用表单验证器,它考虑两个输入的值(在我的例子中是“贷款类型”和“贷款目标”选择)而且永远不需要从表单中删除。我不会在这方面花费更多时间,但如果可以的话,请随意回答原始问题!我认为表单验证程序不仅仅是一种解决方法,它们是正确的答案。它们专门用于处理涉及多个输入值的验证。@biziclop,谢谢!如果您想将其添加为一个答案,也许稍微详细一点,我会接受。是的,这样的方法;这就是问题所在。