为了实现我想要的,我必须重写 Insert 的renderComponent
方法。这只是因为 Tapestry 4.0.2 没有setStyleClass
方法。它看起来基本上像
if (!cycle.isRewinding()) {
Object value = getValue();
if (value != null) {
String styleClass;
String insert = null;
Format format = getFormat();
if (format == null) {
insert = value.toString();
}
else {
insert = format.format(value);
}
styleClass = getStyleClass();
if (styleClass == null) {
/* No classes specified */
styleClass = MY_CLASS;
}
else {
/* Append the preserveWhiteSpace class to the string listing the style classes. */
styleClass += " " + MY_CLASS;
}
if (styleClass != null) {
writer.begin("span");
writer.attribute("class", styleClass);
renderInformalParameters(writer, cycle);
}
writer.print(insert, getRaw());
if (styleClass != null) {
/* </span> */
writer.end();
}
}
}
}
如果我们有一个 setStyleClass 方法,我们就可以完成
setStyleClass(MY_CLASS);
super.renderComponent;