当组件有一个wicket:id时,如何输出类标签? [英] How to output the class tag when the component has a wicket:id?

查看:374
本文介绍了当组件有一个wicket:id时,如何输出类标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个Wicket新手。我想知道是否有人可以帮我解决以下问题:
我有:

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

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

和:

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

但表格的类 centredtab 是没有被渲染。 Wicket API中是否有一个方法可以确保呈现此类属性以使表单居中?

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?

谢谢!

推荐答案

Wicket简单属性appender拯救你在这里看到 http://wicket.apache.org/apidocs/1.4/org/apache/wicket/behavior/AttributeAppender.html

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

基本上,

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






好的。我想你错过了参数 addAttributeIfNotPresent (参考上面的文档)

试试这个

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

报价


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

创建一个AttributeModifier,它将appendModel的值附加到属性的当前值,并在addAttributeIfNotPresent为true时添加该属性。

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.

希望这会有所帮助。

这篇关于当组件有一个wicket:id时,如何输出类标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆