java Wicket 更改标签/文本字段值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15919721/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Wicket change label/textfield value
提问by Alex
I am trying to learn Wicket. One of the problems I encounter, is changing the values of components like a label.
我正在尝试学习 Wicket。我遇到的问题之一是更改标签等组件的值。
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?
有没有更好/更简单的方法来编辑 Wicket 标签的值并向用户显示这个新值?
Thanks!
谢谢!
回答by Cedric Gatay
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
在你的 ajax 事件中
strMdl.setObject("My new message");
target.add(msg);