【发布时间】:2018-09-21 12:57:51
【问题描述】:
当数据项从服务器通过调度程序返回到 Presenter(客户端)时,数据项布尔标志不会保持其状态。
共享包
public class ResourceItem extends BaseResourceItem implements IsSerializable {
private String name;
public ResourceItem() {
super();
}
public ResourceItem(String name) {
super(true);
this.name = name;
}
}
public class BaseResourceItem {
private boolean removeEnabled = true;
public BaseResourceItem() {
super();
}
public BaseResourceItem(boolean removeEnabled) {
super();
this.removeEnabled = removeEnabled;
}
public boolean isRemoveEnabled() {
return removeEnabled;
}
public void setRemoveEnabled(boolean removeEnabled) {
this.removeEnabled = removeEnabled;
}
}
有问题的标志是 removeEnabled 。默认情况下它是 true,即使我在服务器端将它设置为 false,当 Presenter 获取它时,由于某种原因它被设置为 false。我错过了序列化的东西吗? (此时想不出别的)。
服务器包
@GenDispatch
public class GetModelSettings {
@Out(1)
List<ResourceItem> listOfSettings;
}
public class GetModelSettingsHandler implements ActionHandler<GetModelSettingsAction, GetModelSettingsResult> {
@Override
public GetModelSettingsResult execute(GetModelSettingsAction action, ExecutionContext context)
throws ActionException {
ResourceItem item1 = new ResourceItem();
ResourceItem item2 = new ResourceItem();
item2.setRemoveEnabled(false);
list.add(item1);
list.add(item2);
// item1 -> true
// item2 -> false
return new GetModelSettingsResult(list);
}
}
如您所见,一个简单的处理程序返回一个列表。至此,数据是正确的,一项设置为真,另一项设置为假。
客户端包
public class ModelSettingsPresenter {
dispatcher.execute(new GetModelSettingsAction(), new AsyncCallback<GetModelSettingsResult>() {
@Override
public void onSuccess(GetModelSettingsResult result) {
itemList = result.getListOfSettings();
// itemList.get(0) -> true
// itemList.get(1) -> true
}
});
}
在此演示器中,数据项的标志都设置为 true。任何想法为什么会发生这种情况?
【问题讨论】: