Wicket: change AjaxButton text to submit

I am new to Wicket and trying to change AjaxButton text to submit. So the idea is that the first time the page loads, the user sees an AjaxButton with the caption, for example. "1" by clicking on the button, the button label will change to "2", and after the next click on "3" and so on ... It may not be difficult, but as I said, I'm noobie when it comes to gates. All help is appreciated!

form.add(new AjaxButton("ajax-button", form)
    {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form)
        { //how to change Button label here?
         }

}

+3
source share
2 answers

The answer is simple: use a model.

        //counter field declared in page class
        private int counter;

            ...

    form.add(new AjaxButton("ajax-button", new PropertyModel<String>(this,
            "counter", form)) {

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            counter++;
            target.addComponent(this);

        }
    });

, , Wicket: - , . , , "" Swing.

N.b.: , .

+8

biziclop, .

Java-:

AjaxButton yourButton = new AjaxButton("btnId"){
//your button implementation goes here
};
int yourVariable = 42;
Label yourLabel = new Label("labelId", new Model<String>() {
        public String getObject() {
            String text = MessageFormat.format(new Localizer().getString("IdForLocalizerInYourLocalizerFile", null), yourVariable);
            return text;
        }
    })
yourButton.add(yourLabel);

html:

  <a type="submit" wicket:id="btnId">
    <span wicket:id="labelId">[This text will never be seen, will be replaced by "The var..."]</span>
  </a>

, :

IdForLocalizerInYourLocalizerFile= The variable value is {0}. It will be replaced whenever it changes and button component is added to target. Text will remain.
0

All Articles