Peter
Peter

Reputation: 45

how to add a onclick(onchange) event for a wicket radiobutton?

how to add a onclick(onchange) event for a wicket radiobutton?

Likes add a onclick() for button:

add(new Button("search") {
            @Override
            public void onSubmit() {
    ……
  }

I try it with below way, but can’t work:

Radio<String> radio = new Radio<String>("aaa", new Model<String>("AAA") {
          @Override
            public void onClick() {
            ……
          }
 });

Upvotes: 0

Views: 2999

Answers (2)

soorapadman
soorapadman

Reputation: 4509

Wicket radio button doesn't have onclick override method . So the best way it could be

Radio<String> radio  = new Radio<String>("aaa", new Model<String>("AAA"));
        radio.add(new AjaxFormSubmitBehavior("click") {
            @Override
            protected void onEvent(AjaxRequestTarget target) {
                //Your action whatever you want to do
            }
        });

Note: This radio should have form around it.And add this to radio group .

Upvotes: 1

Andrea Del Bene
Andrea Del Bene

Reputation: 2511

if you need to do something on server side when onchange is fired, maybe the best solution is to add a AjaxEventBehavior to your radio buttons:

radioGroup.add(new AjaxEventBehavior("change") {
  protected void onEvent(AjaxRequestTarget target) {
      System.out.println("ajax here!");
  }
 }

Upvotes: 0

Related Questions