且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Wicket中更改链接文本?

更新时间:2023-12-01 15:08:52

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)