6

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!

Alex
  • 223
  • 1
  • 6
  • 21

1 Answers1

23

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);
Cedric Gatay
  • 1,553
  • 3
  • 12
  • 17
  • Thank you for your answer. I did not understand them, but now I do. This is working perfectly – Alex Apr 10 '13 at 10:36