I created a new testcase, which shows a problem I got more clearly than in other posts of mine.
I have the following code:
TestModule
worldDSExport:
worldDSExport2:
TestDMIHandler
Note the
and
in the DS.xml files.
So the first listgrid shows all records, and the second one only the records with shouldShow=1.
In my database I got two records:
pk, countryCode, countryName, shouldShow
1, de, Germany, True
2, us, USA, True
So both countries are shown in both grids, which is correct.
Then I press the button. This button changes the "shouldShow" of record 1 to False.
This is correct, the record is changed.
But STILL BOTH records are in BOTH listgrids, although the second listGrid should only show records with shouldShow=True.
Why is this happening?
How could I update the second grid using updateData() and respecting its criteria ?
I am using SmartGWT 4.0: v9.0p_2013-10-17/PowerEdition Deployment (built 2013-10-17)
I have the following code:
TestModule
Code:
public class TestingModule implements EntryPoint { public void onModuleLoad() { final ListGrid countryList = new ListGrid(); countryList.setWidth(500); countryList.setAlternateRecordStyles(true); countryList.setDataSource(DataSource.get("worldDSExport")); countryList.setAutoFetchData(true); ListGridField pk = new ListGridField("pk"); pk.setHidden(true); ListGridField countryName = new ListGridField("countryName", "Country"); ListGridField capital = new ListGridField("capital", "Capital"); ListGridField shouldShow = new ListGridField("shouldShow", "Should show"); countryList.setFields(pk, countryName, capital, shouldShow); countryList.setAutoFitData(Autofit.VERTICAL); countryList.setShowFilterEditor(true); countryList.setAutoFitMaxRecords(10); VLayout layout = new VLayout(15); layout.setHeight(300); HLayout formLayout = new HLayout(15); IButton addBtn = new IButton("Press"); addBtn.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { Record updateRecord = new Record(); updateRecord.setAttribute("pk", 1); updateRecord.setAttribute("shouldShow", false); DataSource.get("worldDSExport").updateData(updateRecord); } }); formLayout.addMember(addBtn); layout.addMember(formLayout); layout.addMember(countryList); final ListGrid countryList2 = new ListGrid(); countryList2.setWidth(500); countryList2.setAlternateRecordStyles(true); countryList2.setDataSource(DataSource.get("worldDSExport2")); countryList2.setAutoFetchData(false); ListGridField pk2 = new ListGridField("pk"); pk2.setHidden(true); ListGridField countryName2 = new ListGridField("countryName", "Country"); ListGridField capital2 = new ListGridField("capital", "Capital"); ListGridField shouldShow2 = new ListGridField("shouldShow", "Should show"); countryList2.setFields(pk2, countryName2, capital2, shouldShow2); countryList2.setAutoFitData(Autofit.VERTICAL); countryList2.setShowFilterEditor(true); countryList2.setAutoFitMaxRecords(10); Criteria c2Criteria = new Criteria(); c2Criteria.addCriteria("filterContinent", "true"); countryList2.fetchData(c2Criteria); layout.addMember(countryList2); layout.draw(); } }
Code:
<DataSource ID="worldDSExport" tableName="worldDS" serverType="sql" > <fields> <field name="pk" type="integer" hidden="true" primaryKey="true" /> <field name="countryCode" type="text" required="true" /> <field name="countryName" type="text" required="true" /> <field name="capital" type="text" /> <field name="government" type="text" length="500" /> <field name="continent" type="text" > </field> <field name="independence" type="date" /> <field name="area" type="float" /> <field name="population" type="integer" /> <field name="gdp" type="float" /> <field name="member_g8" type="boolean" /> <field name="shouldShow" type="boolean" sqlStorageStrategy="number" /> </fields> <operationBindings> <operationBinding operationType="update"> <serverObject className="zedes2.server.dmi.TestDMIHandler" methodName="doUpdate" /> </operationBinding> </operationBindings> </DataSource>
Code:
<DataSource ID="worldDSExport2" tableName="worldDS" serverType="sql" > <fields> <field name="pk" type="integer" hidden="true" primaryKey="true" /> <field name="countryCode" type="text" required="true" /> <field name="countryName" type="text" required="true" /> <field name="capital" type="text" /> <field name="government" type="text" length="500" /> <field name="continent" type="text" > </field> <field name="independence" type="date" /> <field name="area" type="float" /> <field name="population" type="integer" /> <field name="gdp" type="float" /> <field name="member_g8" type="boolean" /> <field name="shouldShow" type="boolean" sqlStorageStrategy="number" /> </fields> <operationBindings> <operationBinding operationType="fetch" > <whereClause> shouldShow=1 AND ($defaultWhereClause) </whereClause> </operationBinding> <operationBinding operationType="fetch" operationId="fetch_simple" > <whereClause> ($defaultWhereClause) </whereClause> </operationBinding> </operationBindings> </DataSource>
Code:
public class TestDMIHandler { public DSResponse doUpdate(DSRequest dsRequest, HttpServletRequest servletRequest) throws Exception { DSResponse response = dsRequest.execute(); Integer pk = (Integer) response.getRecord().get("pk"); DSRequest newRequest = new DSRequest("worldDSExport2", DataSource.OP_FETCH); newRequest.setOperationId("fetch_simple"); newRequest.setCriteria("pk", pk); newRequest.setRPCManager(dsRequest.getRPCManager()); DSResponse fetchResponse = newRequest.execute(); fetchResponse.setOperationType(DataSource.OP_UPDATE); response.addRelatedUpdate(fetchResponse); return response; } }
Code:
<field name="shouldShow" type="boolean" sqlStorageStrategy="number" />
Code:
<operationBinding operationType="fetch" > <whereClause> shouldShow=1 AND ($defaultWhereClause) </whereClause> </operationBinding>
So the first listgrid shows all records, and the second one only the records with shouldShow=1.
In my database I got two records:
pk, countryCode, countryName, shouldShow
1, de, Germany, True
2, us, USA, True
So both countries are shown in both grids, which is correct.
Then I press the button. This button changes the "shouldShow" of record 1 to False.
This is correct, the record is changed.
But STILL BOTH records are in BOTH listgrids, although the second listGrid should only show records with shouldShow=True.
Why is this happening?
How could I update the second grid using updateData() and respecting its criteria ?
I am using SmartGWT 4.0: v9.0p_2013-10-17/PowerEdition Deployment (built 2013-10-17)
Comment