gpt4 book ai didi

java - 如何更改 Wicket 中 AjaxEditableLabelColumn 单元格的颜色

转载 作者:行者123 更新时间:2023-12-02 06:27:21 25 4
gpt4 key购买 nike

我有一个带有 onChange 方法的 AjaxEditableLabelColumn 。我需要更改刚刚编辑的单元格的背景颜色。这是代码:

private AjaxEditableLabelColumn<User, String> createMyEditableColumn(String propertyExpression, boolean sortable) {
AjaxEditableLabelColumn<User, String> column = new AjaxEditableLabelColumn<User, String>(propertyExpression, sortable) {
private static final long serialVersionUID = 1L;

@Override
protected void onChange(AjaxRequestTarget target, IModel<User> model) {

User newRecord = model.getObject();

if (newRecord.hasChanged()) {
if (newRecord.isRight()) {
((((TURN GREEN))))
} else {
((((TURN RED)))))
}

} else {
((((REMOVE COLOR))))
}
}

};
return column;
}

最佳答案

我建议您只添加一个属性修饰符行为并更改 css 类或样式属性的模型。

代码:

    private AjaxEditableLabelColumn<User, String> createMyEditableColumn(String propertyExpression, boolean sortable) {

final IModel<String> cssModel = Model.of("bkg-default");
AjaxEditableLabelColumn<User, String> column = new AjaxEditableLabelColumn<User, String>(propertyExpression, sortable) {

private static final long serialVersionUID = 1L;

@Override
protected void onChange(AjaxRequestTarget target, IModel<User> model) {

User newRecord = model.getObject();

if (newRecord.hasChanged()) {
if (newRecord.isRight()) {
cssModel.setObject("bkg-green");
} else {
cssModel.setObject("bkg-red");
}
} else {
cssModel.setObject("bkg-default");
}
}
// The following line is unnccessary if you already add
// component for to be render in AjaxEditableLabelColumn
target.add(this);

};
column.add(new AttributeModifier("css", cssModel));
return column;
}

CSS:

.bkg-default { background-color: transparent; }
.bkg-green { background-color: green; }
.bkg-red { background-color: red; }

关于java - 如何更改 Wicket 中 AjaxEditableLabelColumn 单元格的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20401486/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com