开发者

How to set displayed text for a HTML anchor tag using Wicket?

I would like to dynamically change the text displayed for a HTML anchor tag. So, for example if I have the following in my markup -

<a class="point" style="font-family:courier" wicket:id="link">[+]</a>

I want to change the '[+]' to something else. Currently the code fragment looks like this:

            equipmentFamilyName.add(new Link<String>("link") {

                @Override
                protected void onComponentTag(ComponentTag tag) {
                    String id = "link" + equipmentFamilyName.getModelObject();
                    tag.put("onclick", "toggle('" + collapsibleId + "','" + id + "')");
                    tag.put("id", id);
                }

            @Override
            public void onClick() {

            }
            });

Which just adds various attributes. I tried using a model associated with the Link object like this

            IModel<String> linkModel = new Model<String>("-");
            equipmentFamilyName.add(new Link<String>("link", linkModel) {
                ...
开发者_JAVA百科

But that had no effect on the displayed text i.e. I still get '[+]' shown on my web page. Any suggestions or code examples clarifying how to do this would be much appreciated.

Edit: Following the pointers in the comments, I added a method to override onComponentTagBody(). I now have a solution to this for our current version of Wicket (1.4.17).

                @Override
                protected void onComponentTagBody(final MarkupStream markupStream, final ComponentTag openTag) {
                    replaceComponentTagBody(markupStream, openTag, "[-]");
                }


If you use Wicket 1.5 then this is quite easy: link.setBody(IModel). The model's object will be used as link's body.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜