爲了實現我想要的,我必須重寫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;