如何在Wicket中用多个值替换属性的属性值?

时间:2012-09-11 19:09:18

标签: wicket

我的class属性有两个CSS类值。 HTML开头是这样的:

<input type="button" wicket:id="rowButton" class="jelly-button greenGradient"/>

我想动态地改变它:

<input type="button" wicket:id="rowButton" class="jelly-button redGradient"/>

目前我这样做:

  

component.add(new SimpleAttributeModifier(“class”,“jelly-button redGradient”));

在Wicket中执行此操作的最佳方式是什么?必须有一种比我上面所做的更“恰当”的方式。

2 个答案:

答案 0 :(得分:7)

您可以使用带有从模型中检索的文本的属性appender,而不是使用带有固定文本的属性修饰符。要更改类,只需更改模型的值即可。例如:

Model<String> gradientModel = new Model<String>("greenGradient");

...

component.add(AttributeModifier.append("class", gradientModel));
标记中的

只有

<input type="button" wicket:id="rowButton" class="jelly-button"/>

然后当需要更改渐变时使用

gradientModel.setObject("redGradient");

gradientModel.setObject("greenGradient");

答案 1 :(得分:0)

相关问题