Hello,
I've been trying to test Parent Child relations in SmartGWT. I couldn't find any helpful information/tutorials on foreign Keys with SQL datasources in GWT. While I'm no database expert I tested out constraints and small projects on my dataset and it appears my foreign Keys work as expected in the database and a few small test widgets.
I used the BuiltInDS to try to see if I can mimic the "transactions"
http://www.smartclient.com/smartgwte...ions_queued_md with my own dataset. I thought it would be a straightforward process since I've used these datasets in samples such as master Detail
http://www.smartclient.com/smartgwt/..._master_detail
I'm not concerned with processing but specifically the grid relations.
Since I am working with sensitive data I had to make some changes to the code of course
**explaination after the code
parent Datesource
Child DataSource
I wanted the user to select the first field "name" (Parent Name) and depending on the item they selected populate the "parent" (Children options)
("parent" is of course my foreign Key established in ds.xml as well as mysql)
The method I have seems to pull the first field as expected but allows all rows to be shown regardless of the first option. This happens for field column I put in the child except for the "name".
When I use name it wont populate the second field with names but copy the first field over. When I try to edit that option it shows all of my parentType(foreignKey) which is odd. Even after I cleared my browser cache and restarted the app to be sure this will still happen consistently.
I ordered a book in efforts to hopefully understand this software a little better. Is there anything in this code that seems blatantly culprit? I don't think its a bug. I have a feeling it's how I'm addressing the foreign keys in the ds.xml file. Also are there in good in-depth materials aside from the quickStart guide that may be of use to this?
Thanks for any help in advance
SmartClient Version: SC_SNAPSHOT-2011-12-05/EVAL Deployment
tested in IE9(Compatibility view on and off) and Chrome
I've been trying to test Parent Child relations in SmartGWT. I couldn't find any helpful information/tutorials on foreign Keys with SQL datasources in GWT. While I'm no database expert I tested out constraints and small projects on my dataset and it appears my foreign Keys work as expected in the database and a few small test widgets.
I used the BuiltInDS to try to see if I can mimic the "transactions"
http://www.smartclient.com/smartgwte...ions_queued_md with my own dataset. I thought it would be a straightforward process since I've used these datasets in samples such as master Detail
http://www.smartclient.com/smartgwt/..._master_detail
I'm not concerned with processing but specifically the grid relations.
Since I am working with sensitive data I had to make some changes to the code of course
**explaination after the code
parent Datesource
Code:
//parentTable <DataSource ID="parentTableSQL" serverType="sql" tableName="parentTable" > <fields> <field name="id" hidden="true" type="text" required="true" rootValue="root" foreignKey="parentTableSQL.name" length="128" /> <field name="name" title="Parent" type="text" length="128" primaryKey="true" required="true"/> </fields> </DataSource>
Child DataSource
Code:
//childTable <DataSource ID="childTableSQL" serverType="sql" tableName="childTable" > <fields> <field name="id" type="sequence" hidden="true" primaryKey="true"/> <field name="name" title="Name" type="text" length="128" required="true"/> <field name="parent" title="Parent FK" type="text" length="128" foreignKey="parentTableSQL.name" required="true"/> </fields> </DataSource>
Code:
import com.smartgwt.client.data.DataSource; import com.smartgwt.client.rpc.RPCManager; import com.smartgwt.client.rpc.RPCRequest; import com.smartgwt.client.rpc.QueueSentCallback; import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.IButton; import com.smartgwt.client.widgets.Label; import com.smartgwt.client.widgets.events.ClickEvent; import com.smartgwt.client.widgets.events.ClickHandler; import com.smartgwt.client.widgets.form.DynamicForm; import com.smartgwt.client.widgets.form.fields.SelectItem; import com.smartgwt.client.widgets.grid.ListGrid; import com.smartgwt.client.widgets.grid.ListGridField; import com.smartgwt.client.widgets.grid.ListGridRecord; import com.smartgwt.client.widgets.layout.HLayout; import com.smartgwt.client.widgets.layout.VLayout; import com.google.gwt.user.client.Timer; import java.util.HashMap; import java.util.Map; import com.google.gwt.core.client.EntryPoint; public class OneToOne2 extends VLayout { //passed "parTypeSQL","childTableSQL" through the constructor public OneToOne2(String dsPar, String dsChild) { DataSource parDs = DataSource.get(dsPar); DataSource childDs = DataSource.get(dsChild); final DynamicForm form = new DynamicForm(); form.setWidth(300); form.setDataSource(parDs); form.setUseAllDataSourceFields(true); final ListGrid listGrid = new ListGrid(); listGrid.setHeight(224); listGrid.setWidth100(); listGrid.setCanEdit(true); listGrid.setAutoSaveEdits(false); ListGridField parField = new ListGridField("name", "Parent Name"); SelectItem parSelectItem = new SelectItem(); parSelectItem.setOptionDataSource(parDs); parField.setEditorType(parSelectItem); ListGridField childField = new ListGridField("parent", "Children"); SelectItem childSelectItem = new SelectItem(); childSelectItem.setOptionDataSource(childDs); childField.setEditorType(childSelectItem); ListGridField qtyField = new ListGridField("quantity", "Qty", 30); listGrid.setFields(qtyField, parField, childField); IButton addButton = new IButton("Add Contact Line"); addButton.setWidth(110); addButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { Map defaults = new HashMap(); defaults.put("quantity", 1); listGrid.startEditingNew(defaults); } }); IButton saveButton = new IButton("Save contact"); saveButton.setWidth(100); saveButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { RPCManager.startQueue(); form.saveData(); listGrid.saveAllEdits(); RPCManager.sendQueue(); form.editNewRecord(); listGrid.setData((ListGridRecord[])null); SC.say("Order saved in single batch."); } }); HLayout hLayout = new HLayout(10); hLayout.addMember(addButton); hLayout.addMember(saveButton); VLayout layout = new VLayout(20); layout.setAutoHeight(); layout.addMember(form); layout.addMember(listGrid); layout.addMember(hLayout); final ServerCountLabel serverCountLabel = new ServerCountLabel(); layout.addMember(serverCountLabel); RPCManager.setQueueSentCallback(new QueueSentCallback() { public void queueSent(RPCRequest[] requests) { serverCountLabel.incrementAndUpdate(requests); //flash the label serverCountLabel.setBackgroundColor("ffff77"); new Timer() { public void run() { serverCountLabel.setBackgroundColor("ffffff"); } }.schedule(500); } }); layout.draw(); this.addMember(form); this.addMember(listGrid); this.addMember(hLayout); this.addMember(layout); // this.addMember(itemField); } class ServerCountLabel extends Label { private int count = 0; ServerCountLabel() { setPadding(10); setWidth(300); setHeight(40); setBorder("1px solid grey"); setContents("<b>Number of server trips: 0<br>No queues sent</b>"); } public void incrementAndUpdate(RPCRequest[] requests) { count++; setContents("<b>Number of server trips: " + count + "<br/>Last queue contained: " + requests.length + " request(s)</b>"); } } }
("parent" is of course my foreign Key established in ds.xml as well as mysql)
The method I have seems to pull the first field as expected but allows all rows to be shown regardless of the first option. This happens for field column I put in the child except for the "name".
When I use name it wont populate the second field with names but copy the first field over. When I try to edit that option it shows all of my parentType(foreignKey) which is odd. Even after I cleared my browser cache and restarted the app to be sure this will still happen consistently.
I ordered a book in efforts to hopefully understand this software a little better. Is there anything in this code that seems blatantly culprit? I don't think its a bug. I have a feeling it's how I'm addressing the foreign keys in the ds.xml file. Also are there in good in-depth materials aside from the quickStart guide that may be of use to this?
Thanks for any help in advance
SmartClient Version: SC_SNAPSHOT-2011-12-05/EVAL Deployment
tested in IE9(Compatibility view on and off) and Chrome
Comment