hudi
hudi

Reputation: 16555

How to add behavior to dropDownChoice inside of form

I have form with fields:

    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) {
                       ...
                    }
                });
}

this code thrown exception:

Behavior cz.isvs.reg.rob.monitor.web.VyjimkyPage$VyjimkyForm$1 can only be added to an instance of a FormComponent. WHy I cant add this behavior ? this drop choice is in form

when I run this code this exception is thrown:

Upvotes: 2

Views: 1176

Answers (1)

Nicktar
Nicktar

Reputation: 5575

You misplaced a closing bracket.

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

        private static final long serialVersionUID = 1L;

            @Override
            protected void onUpdate(AjaxRequestTarget target) {
                       ...
        }
    }));

should do the trick.

With your placement of the brackets you were trying to add the behaviour to the enclosing component.

Upvotes: 4

Related Questions