How to output the class tag when the component has a wicket:id?

独自空忆成欢 提交于 2019-12-08 07:07:26

问题


I'm a Wicket newbie. I wonder if someone could help me with the following: I have:

.centredtab{
margin-left: auto;
margin-right: auto;
}

and:

 <form class="centredtab"wicket:id="questionform">

but the class centredtab for the form is not being rendered. Is there a method in the Wicket API to ensure that this class attribute will be rendered in order that the form is centred?

Thanks!


回答1:


Wicket simple attribute appender to rescue you see here http://wicket.apache.org/apidocs/1.4/org/apache/wicket/behavior/AttributeAppender.html

Essentially,

  myForm.add(new AttributeAppender("class", 
             new Model<String>("centredtab"), " "));

alright. I think you're missing the parameter addAttributeIfNotPresent (refer the doc above)

Try this

   myForm.add(new AttributeAppender("class", true, 
                                     new Model<String>("centredtab"), " "));

As quoted

AttributeAppender(String attribute, boolean addAttributeIfNotPresent, 
                                IModel<?> appendModel, String separator)

Creates an AttributeModifier that appends the appendModel's value to the current value of the attribute, and will add the attribute when addAttributeIfNotPresent is true.

should solve your issue of not creating the attribute.

Hope this helps.



来源:https://stackoverflow.com/questions/4891639/how-to-output-the-class-tag-when-the-component-has-a-wicketid

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