WicketのHTMLタグに属性を動的に追加する
Wicketでは、HTMLタグに簡単にアクセスしたり操作したりすることができます。たとえば、HTMLテキストボックスコンポーネントがあり、divタグで囲み、テキストボックスの検証に失敗した場合はdivタグをエラーカラーでハイライト表示する必要があります。
上記の場合、属性をHTMLタグに動的に追加するために ”
AbstractBehavior
“クラスを実装することができます。次の例を参照してください。
元のHTML
Hello ~ Wicket leaning curve is high, do you?
Wicketを使用した
Modify AbstractBehavior
WebMarkupContainerWithAssociatedMarkup divtest =
new WebMarkupContainerWithAssociatedMarkup("wicket__id__test");
//validation failed , add AbstractBehavior to the div test container
divtest.add(new AbstractBehavior() {
public void onComponentTag(Component component, ComponentTag tag) {
tag.put("style", "background-color:red");
}
});
Resultこのように:
Hello ~ this is testing for adding attribute into above tag in Wicket ~