如何在Wicket中更改链接文本? [英] How do I change link-text in Wicket?
本文介绍了如何在Wicket中更改链接文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经做到这一点:
add(new Link(doAnything){
@Override
public void onClick(){
//更改文本!
// this.modelChanging();
// this.detach();
}
});
我希望你能给我一些简单的建议 - 我真的很新: p>
最好的问候
Elias
解决方案
HTML: p>
< html>< head>< / head>< body>
< wicket:panel>
< a href =wicket:id =link>
< wicket:container wicket:id =label/>
< / a>
< / wicket:panel>
< / body>< / html>
java:
public class MyPanel extends Panel {
private static class Mybean {
String labelText =click me;
public String getLabelText(){
return this.labelText;
}
public void setLabelText(final String labelText){
this.labelText = labelText;
}
}
public MyPanel(final String id){
super(id);
final Mybean bean = new Mybean();
this.add(new Link< Void>(link){
private static final long serialVersionUID = 1L;
@Override
public void onClick(){
bean.setLabelText(感谢点击);
}
} .add(new Label(label,new PropertyModel< String>(bean,labelText )))
);
}
}
我倾向于使用wicket:容器,以便不用多余元素污染HTML(小门:容器不会在生产中呈现)
I created a link with static text. That works fine but now I also want to change the text when you click the link.
I got as far as this:
add(new Link("doAnything") {
@Override
public void onClick() {
// change the text!
// this.modelChanging();
// this.detach();
}
});
I hope you can give me some easy advice - I'm really new to this :)
Best regards Elias
解决方案
The HTML:
<html><head></head><body>
<wicket:panel>
<a href="" wicket:id="link">
<wicket:container wicket:id="label" />
</a>
</wicket:panel>
</body></html>
The java:
public class MyPanel extends Panel{
private static class Mybean{
String labelText = "click me";
public String getLabelText(){
return this.labelText;
}
public void setLabelText(final String labelText){
this.labelText = labelText;
}
}
public MyPanel(final String id){
super(id);
final Mybean bean = new Mybean();
this.add(new Link<Void>("link"){
private static final long serialVersionUID = 1L;
@Override
public void onClick(){
bean.setLabelText("Thanks for clicking");
}
}.add(new Label("label", new PropertyModel<String>(bean, "labelText")))
);
}
}
I tend to use wicket:container in order to not pollute the HTML with superfluous elements (the wicket:container won't be rendered in production)
这篇关于如何在Wicket中更改链接文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文