我有一个表单,我需要动态添加/删除验证器。根据下拉选择,其他表单字段可能具有不同的验证规则。
对于其他类型的输入,我使用replace(methodThatCreatesTheInput())
来摆脱以前添加的验证器。 (不知道更好的方法。具体来说,似乎没有任何方法可以直接从组件中删除验证器......)
使用 Select ,来自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;
}
(为什么使用Select而不是普通的DropDownChoice?我们希望两种类型的选择明确分开,as documented in this question。)
任何想法如何解决这个问题?我想要实现的目标当然非常简单。不幸的是,Wicket不同意,或者我错了。
Wicket 1.4。