Change tag label / text field

I am trying to learn Wicket. One of the problems I am facing is changing the values ​​of components, such as a label.

This is how I declare a 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 the Wicket tag and display this new value to the user?

Thank!

+5
source share
1 answer

I think you did not understand what Models are. Your example can 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);
+19
source

All Articles