編集:
SmartGWT/PureMVC プロジェクトがあります。MyMediator の initView() で、DataSource を使用して ListGrid を作成します。それはよく示しています。ここに myDataSource コードがあります:
public class MyDataSource extends DataSource {
private static MyDataSource instance;
private static final String COLUMN_ONE = "One";
private static final String COLUMN_TWO = "Two";
public static MyDataSource getInstance() {
if (instance == null) instance = new MyDataSource("ID");
return instance;
}
private MyDataSource(String id) {
setDataProtocol(DSProtocol.CLIENTCUSTOM);
setDataFormat(DSDataFormat.CUSTOM);
setClientOnly(false);
constructDataSource(id);
}
private void constructDataSource(String id) {
setID(id);
DataSourceTextField one = new DataSourceTextField(COLUMN_ONE);
DataSourceTextField two= new DataSourceTextField(COLUMN_TWO);
setFields(one, two);
}
protected Object transformRequest(DSRequest request){
DSResponse response = new DSResponse();
response.setAttribute("clientContext", request.getAttributeAsObject("clientContext"));
response.setStatus(0);
switch (request.getOperationType()) {
case FETCH:
executeFetch(request.getRequestId(), request, response);
// and the other operation types
}
return request.getData();
}
protected void executeFetch(final DSRequest request, final DSResponse response) {
// call Async method to fetch data from database
// do response.setData() with the list of records received
// processResponse(request.getRequestId(), response)
}
}
initView() で作成した myListGrid には次の設定があります。
// myDataSource is a private field of myMediator, so that I can access it in the notifications
myDataSource = MyDataSource.getInstance();
myListGrid.setShowRecordComponents(true);
myListGrid.setShowRecordComponentsByCell(true);
myListGrid.setDataSource(myDataSource);
myListGrid.setCanEdit(false);
myListGrid.setCanCollapseGroup(false);
myListGrid.setFreezeFields(false);
myListGrid.setCanGroupBy(false);
myListGrid.setCanMultiSort(false);
myListGrid.setCanSort(false);
myListGrid.setCanAutoFitFields(false);
myListGrid.setCanResizeFields(false);
myListGrid.setCanPickFields(false);
myListGrid.setAutoFetchData(false);
// fetchData() in an onDraw handler
// upon first launch, column "One" should be hidden
myDataSource.getField(MyDataSource.COLUMN_ONE).setHidden(true);
ここまでは、すべて問題ありません。次に、何らかの通知があったときに、継承された PureMVC の handleNotification メソッドで非表示の列を表示したいと思います。
// Test 1
myDataSource.getField(MyDataSource.COLUMN_ONE).setHidden(false); // not working
// Test 2
myDataSource.getField(MyDataSource.COLUMN_ONE).setHidden(false);
myListGrid.redraw(); // not working
// Test 3
myDataSource.getField(MyDataSource.COLUMN_ONE).setHidden(false);
myListGrid.refreshFields(); // not working
// Test 4
myDataSource.getField(MyDataSource.COLUMN_ONE).setHidden(false);
myDataSource.invalidateCache(); // not working
// Test 5
myDataSource.destroy();
myDataSource = MyDataSource.getInstance();
myListGrid.setDataSource(myDataSource);
myListGrid.fetchData(); // not working because getInstance() method returns the old instance in which the column is hidden
// Test 6
myListGrid.setShowHiddenFields(true); // not working
したがって、列は常に非表示のままです。助けてください!