Wicket change label/textfield value
Asked Answered
L

1

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!

Loutitia answered 10/4, 2013 at 7:37 Comment(0)
C
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);
Canaan answered 10/4, 2013 at 7:44 Comment(1)
Thank you for your answer. I did not understand them, but now I do. This is working perfectlyLoutitia

© 2022 - 2024 — McMap. All rights reserved.