I want to refresh a listgrid using addRelatedUpdates(), as you recommend me here:
http://forums.smartclient.com/showthread.php?t=28084
In the "general case", this works well. The second listgrid refreshes correctly after I update the first one.
But in the following scenario, the second listgrid is not being updated.
TestingModule
worldDSExport:
worldDSExport2:
TestDMIHandler
Note the operationBinding which is causing the problem (in worldDSExport2):
In my application I use criteria to control some SQL parts. In this particular case it doesn't make much sense, but in my application I use this, so I created this testcase based on it.
At first, the listGrid is fetch with $criteria.filterContinent set, so "continent = 'Europe' and" is evaluating.
But when updating using addRelatedUpdates(), this seems not to be the case, because the second part ("continent = 'Asia' and") is evaluating.
But that is the whole point? I have a listgrid in my application which takes its records from table A. This listgrid has some criteria like $criteria.filterContinent.
In another part, I update table A, so I need to update the listgrid. But of course, I need the listgrid to maintain its original criteria, I only want to update the record changed.
What am I doing wrong? Why doesn't this work?
I am using SmartGWT 4.0: v9.0p_2013-10-17/PowerEdition Deployment (built 2013-10-17)
http://forums.smartclient.com/showthread.php?t=28084
In the "general case", this works well. The second listgrid refreshes correctly after I update the first one.
But in the following scenario, the second listgrid is not being updated.
TestingModule
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 continent = new ListGridField("continent", "Continent"); countryList.setFields(pk, countryName, capital, continent); 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("Correct capital"); addBtn.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { Record updateRecord = new Record(); updateRecord.setAttribute("pk", 3); updateRecord.setAttribute("capital", "Washington"); 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 continent2 = new ListGridField("continent", "Continent"); countryList2.setFields(pk2, countryName2, capital2, continent2); 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" /> </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" /> </fields> <operationBindings> <operationBinding operationType="fetch" > <whereClause> #if($criteria.filterContinent ) continent = 'Europe' and #else continent = 'Asia' and #end ($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 newListRequest = new DSRequest("worldDSExport2", DataSource.OP_FETCH); newListRequest.setCriteria("pk", pk); newListRequest.setRPCManager(dsRequest.getRPCManager()); DSResponse fetchResponse = newListRequest.execute(); fetchResponse.setOperationType(DataSource.OP_UPDATE); response.addRelatedUpdate(fetchResponse); return response; } }
Code:
<operationBinding operationType="fetch" > <whereClause> #if($criteria.filterContinent ) continent = 'Europe' and #else continent = 'Asia' and #end ($defaultWhereClause) </whereClause> </operationBinding>
At first, the listGrid is fetch with $criteria.filterContinent set, so "continent = 'Europe' and" is evaluating.
But when updating using addRelatedUpdates(), this seems not to be the case, because the second part ("continent = 'Asia' and") is evaluating.
But that is the whole point? I have a listgrid in my application which takes its records from table A. This listgrid has some criteria like $criteria.filterContinent.
In another part, I update table A, so I need to update the listgrid. But of course, I need the listgrid to maintain its original criteria, I only want to update the record changed.
What am I doing wrong? Why doesn't this work?
I am using SmartGWT 4.0: v9.0p_2013-10-17/PowerEdition Deployment (built 2013-10-17)
Comment