[英]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.我想动态更改为 HTML 锚标记显示的文本。 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
我尝试使用与这样的链接 object 关联的 model
IModel<String> linkModel = new Model<String>("-");
equipmentFamilyName.add(new Link<String>("link", linkModel) {
...
But that had no effect on the displayed text ie I still get '[+]' shown on my web page.但这对显示的文本没有影响,即我的 web 页面上仍然显示“[+]”。 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().编辑:按照注释中的指针,我添加了一个方法来覆盖 onComponentTagBody()。 I now have a solution to this for our current version of Wicket (1.4.17).
我现在有一个针对我们当前版本的 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).如果您使用 Wicket 1.5,那么这很容易:link.setBody(IModel)。 The model's object will be used as link's body.
该模型的 object 将用作链接的主体。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.