Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wicket change label/textfield value

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!

like image 534
Alex Avatar asked Apr 10 '13 07:04

Alex


1 Answers

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);
like image 186
Cedric Gatay Avatar answered Nov 16 '22 00:11

Cedric Gatay