How to output the class tag when the component has

2019-05-29 05:19发布

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!

标签: java wicket
1条回答
小情绪 Triste *
2楼-- · 2019-05-29 05:59

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.

查看更多
登录 后发表回答