Wicket: how to use the BodyTagAttributeModifier class?

大城市里の小女人 提交于 2019-12-24 09:03:05

问题


i'm trying to dynamically add the class attribute to the body tag, and i came across this class. but i can't seem to understand how to use this class. i have something like this in my page class (or panel class, as i tried with that too):

add(new BodyTagAttributeModifier("class", "homepage", this));

this doesn't even compile, saying there's something wrong with the 2nd parameter. but i think String is automatically considered a Model in wicket, like the Label class. am i missing something here?


回答1:


What if you just add an wicket:id to the body attribute and use the AttributeAppender class? Or, if the body attribute already has an id, can't you just use this class?

http://wicket.sourceforge.net/apidocs/wicket/behavior/AttributeAppender.html




回答2:


Some Wicket Components have this String-to-model-shortcut (like Label), but it's not a general feature. You have to convert your String into a Model manually:

add(new BodyTagAttributeModifier("class", Model.of("homepage"), this));


来源:https://stackoverflow.com/questions/1247820/wicket-how-to-use-the-bodytagattributemodifier-class

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!