Wicket change label/textfield value

20,315

I think you did not understand what Models are. Your example could be rewritten as follows

Model<String> strMdl = Model.of("My old message");
Label msg = new Label("label", strMdl);
msg.setOutputMarkupId(true);
add(msg);

In your ajax event

strMdl.setObject("My new message");
target.add(msg);
Share:
20,315
Alex
Author by

Alex

Updated on July 05, 2022

Comments

  • Alex
    Alex almost 2 years

    I am trying to learn Wicket. One of the problems I encounter, is changing the values of components like a label.

    This is how I declare the label:

    Label message = new Label("message", new Model<String>(""));
    message .setOutputMarkupId(true);
    add(message );  
    

    The only solution I can find:

    Label newMessage= new Label(message.getId(), "MESSAGE");
    newMessage.setOutputMarkupId(true);
    message.replaceWith(newMessage);
    target.add(newMessage);
    

    Is there a better/easier way to edit the value of a Wicket label and display this new value to the user?

    Thanks!