我有一个GXT 3应用程序,并且试图使用ToggleButtonCell允许用户修改布尔值。
这是数据的代码:
public class InspectionListGridData {
private Boolean posted;
public InspectionListGridData(InspectionListGridData dataToCopy) {
setPosted(dataToCopy.getPosted());
}
public Boolean getPosted() {
return posted;
}
public void setPosted(Boolean posted) {
this.posted = posted;
}
}
为了使网格访问数据,我提供了此属性访问接口:
interface ListProperties extends PropertyAccess<InspectionListGridData> {
ValueProvider<InspectionListGridData, Boolean> posted();
}
Grid&column配置的声明如下:
final ListProperties properties = GWT.create(ListProperties.class);
final List<ColumnConfig<InspectionListGridData,?>> columnConfigList = new ArrayList<ColumnConfig<InspectionListGridData,?>>();
final ListStore<InspectionListGridData> store = new ListStore<InspectionListGridData>(
new ModelKeyProvider<InspectionListGridData>() {
@Override
public String getKey(InspectionListGridData item) {
return item.getInspectionDocumentId().toString();
}
}
});
final ColumnConfig<InspectionListGridData, Boolean> postedColumnConfig = new ColumnConfig<InspectionListGridData, Boolean>(properties.posted(), 5, "Posted");
ToggleButtonCell postedButtonCell = new ToggleButtonCell();
postedButtonCell.setText("posted");
postedButtonCell.setIcon(SafedoorPM.localizedResources.postedIcon());
postedButtonCell.setIconAlign(IconAlign.TOP);
postedColumnConfig.setCell(postedButtonCell);
postedColumnConfig.setSortable(false);
columnConfigList.add(postedColumnConfig);
Grid<InspectionListGridData> inspectionListGrid = new Grid<InspectionListGridData>(store, columnModel);
加载此屏幕时,按钮不会初始化为数据指示的相应状态。 [编辑:初始值加载失败是由于另一个错误。一旦我修复了初始值正确加载的情况]
加载屏幕后,如果我单击一个按钮,它的状态就会改变,但是商店不会更新。我在InspectionListGridData.setPosted()方法上设置了断点,当我单击按钮时未调用该断点。
谁能看到我在做什么错?还是我认为这应该行得错吗?我认为这就是ValueProvider接口的重点。
额外的怪异度,网格在角上显示红色三角形,指示单击时该单元格已变脏,单击时按钮确实显示正确,即保持向下或向上。它似乎似乎没有读取或更新数据存储。
最佳答案
这里有两个问题,起初我只列出了第一个问题(我仍然无法回答,但是更多信息可能会有所帮助),但是第二个问题很清楚。
加载此屏幕时,按钮不会初始化为数据指示的相应状态。
正如我在评论中指出的那样,这令人困惑,并且与我整理的一个快速样本相矛盾。可能是您在绘制网格后更改了数据,而不是通知商店或网格数据已更改,但是如果如果同时使用真值和假值构建数据,则网格应同时显示真值和假值。
我在InspectionListGridData.setPosted()方法上设置了断点,当我单击按钮时未调用该断点。
默认情况下,当store.isAutoCommmit()
为true时,这是默认值,这是预期的。这告诉商店应该将更改排队,而不是将更改直接应用于商店中的对象。这些更改的值在UI中用您注意到的红色三角形标记,其他代码可以通过Store.getRecord(M)
方法或Store.getModifiedRecords()
调用检查更改的值。调用store.commitChanges()
会将它们全部应用到基础模型,或者您可以使用Record.commit()
提交到特定模型。您也可以使用Store.rejectChanges()
或Record.revert()
拒绝更改。
关闭此功能后,应通过单击按钮来调用setPosted方法。不会发生更改跟踪,因此不会在视觉上或在商店记录中设置脏标志。
如果更改已渲染的对象,则有两个(主要)选择-您可以直接通过其设置器修改对象并通知商店,也可以使用商店的记录对象。如果autocommit为false并且调用store.getRecord(object).addChange(properties.posted(), true)
,则将创建setPosted(true)
,而不是创建要提交的新更改,因此,当autocommit为false时,这些方法实际上是相同的。如果直接调用设置器,请确保通过store.update
通知商店对象已更改。
关于java - GXT 3 ToggleButtonCell不更新数据存储,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22672699/