我有以下代码:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd"
xml:lang="en" lang="en">
<body>
<wicket:panel>
<div wicket:id="serviceListContainer">
<table>
<tr wicket:id="serviceListView">
<td>
<span wicket:id="service.name"></span>
</td>
<td>
<span wicket:id="service.state"></span> <!-- I WANT TO COLOR THIS PART IN RED! -->
</td>
</tr>
</table>
</div>
</wicket:panel>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
如何更改将替换"service.state"的输出文本的颜色?我尝试过,<font color="red">但没有任何区别.谢谢!
其他答案表明了如何在HTML模板中添加style="..."属性.另一方面,如果您不希望静态地执行此操作(例如,您需要计算颜色然后将其添加到组件中),则应该向组件1 添加一个.AttributeModifier
示例(未经测试):
Label l = new Label("service.state", ...);
IModel<String> colorModel = new AbstractReadOnlyModel<String>() {
public String getObject() {
return "color: red;"; // Dummy example
}
}; // Some model, holding a string representation of a CSS style attribute (e.g., "color: ...;") based on some date and/or calculation
l.add(new AttributeModifier("style", true, colorModel);
Run Code Online (Sandbox Code Playgroud)
SimpleAttributeModifier如果你不需要基于拉的模型,你甚至可以使用a :
Label l = new Label("service.state", ...);
String styleAttr = "color: red;";
l.add(new SimpleAttributeModifier("style", styleAttr));
Run Code Online (Sandbox Code Playgroud)
1)假如setRenderBodyOnly(true)有没有被调用.这将从<span>输出中删除包装元素.