AttributeModifier

CSSで制御されたHTMLタグの属性(「class=」や「style=」など)
Java側から制御したいと思い、午後からずっと調査していた
のですが、AttributeModifierを用いることでそれが可能になる
ということに気づきました!


HTML側

<li id="event">
    <a wicket:id="linkChoo" href="/" class="">hogehoge</a>
</li>

Java

("linkChoo"というIDの、link1というリンクを生成)
AttributeModifier class_top =
    new AttributeModifier("class", new Model("event-selected"));
link1.add(class_top);
this.add(link1);

しかし、これだとaタグにclass属性が付いてしまうんですよね…
デザイナーの方に、aタグにclass属性を付けられるようにお願い
しているところですが、そっちは可能なのだろうか…


↓実例(4月16日追加)

String url = shop.getURL();
AttributeModifier imgsrc = new AttributeModifier("src", new Model("images/detail/more-shop-info-btn.gif"));
Label label = new Label(Id.image1.ognl(),"");
label.add(imgsrc);
ExternalLink externalLink = new ExternalLink(Id.externalinfo.ognl(), url);
externalLink.add(label.add(RelativePathPrefixHandler.RELATIVE_PATH_BEHAVIOR));
this.add(externalLink.setVisible(url != null));