Java 如何在表单内部向dropDownChoice添加行为

Java 如何在表单内部向dropDownChoice添加行为,java,wicket,Java,Wicket,我有带字段的表单: public VyjimkyForm(final Parametry parametry) { super("vyjimkyForm", new CompoundPropertyModel<Parametry>(parametry)); setOutputMarkupId(true); add(new DropDownChoice<String>("datumy", new Datumy())).

我有带字段的表单:

    public VyjimkyForm(final Parametry parametry) {
        super("vyjimkyForm", new CompoundPropertyModel<Parametry>(parametry));
        setOutputMarkupId(true);
        add(new DropDownChoice<String>("datumy", new Datumy())).add(
                new AjaxFormComponentUpdatingBehavior("onchange") {

                    private static final long serialVersionUID = 1L;

                    @Override
                    protected void onUpdate(AjaxRequestTarget target) {
                       ...
                    }
                });
}
public VyjimkyForm(最终参数){
super(“vyjimkyForm”,新的复合属性模型(parametry));
setOutputMarkupId(真);
添加(新建下拉选项(“datumy”,new datumy())。添加(
新的AjaxFormComponentUpdateingBehavior(“onchange”){
私有静态最终长serialVersionUID=1L;
@凌驾
受保护的void onUpdate(AjaxRequestTarget目标){
...
}
});
}
此代码引发异常:

Behavior cz.isvs.reg.rob.monitor.web.VyjimkyPage$VyjimkyForm$1
只能添加到FormComponent的实例中。为什么我不能添加此行为?这个选择是形式上的


当我运行此代码时,会引发此异常:

您放错了右括号

add(new DropDownChoice<String>("datumy", new Datumy()).add(
    new AjaxFormComponentUpdatingBehavior("onchange") {

        private static final long serialVersionUID = 1L;

            @Override
            protected void onUpdate(AjaxRequestTarget target) {
                       ...
        }
    }));
add(新建下拉选择(“datumy”,new datumy())。添加(
新的AjaxFormComponentUpdateingBehavior(“onchange”){
私有静态最终长serialVersionUID=1L;
@凌驾
受保护的void onUpdate(AjaxRequestTarget目标){
...
}
}));
我们应该做到这一点


在放置括号时,您试图将行为添加到封闭组件。

您将结束括号放错了位置

add(new DropDownChoice<String>("datumy", new Datumy()).add(
    new AjaxFormComponentUpdatingBehavior("onchange") {

        private static final long serialVersionUID = 1L;

            @Override
            protected void onUpdate(AjaxRequestTarget target) {
                       ...
        }
    }));
add(新建下拉选择(“datumy”,new datumy())。添加(
新的AjaxFormComponentUpdateingBehavior(“onchange”){
私有静态最终长serialVersionUID=1L;
@凌驾
受保护的void onUpdate(AjaxRequestTarget目标){
...
}
}));
我们应该做到这一点

在放置括号时,您试图将行为添加到封闭组件中