}
};
public Canvas getViewPanel() {
// Define a couple of simple nested dataSources. Make these client-only for simplicity
DataSource orderItemDS = getOrderItemDS();
DataSource orderDS = getOrderDS();
DynamicForm exampleForm = new DynamicForm();
exampleForm.setID("exampleForm");
exampleForm.setWidth(350);
exampleForm.setHeight(350);
exampleForm.setDataSource(orderDS);
StaticTextItem orderID = new StaticTextItem("orderID");
DateItem orderDate = new DateItem("orderDate");
GridEditorItem items = new GridEditorItem("items");
items.setShowTitle(false);
items.setGridDataSource(orderItemDS);
ListGridField itemDescription = new ListGridField("itemDescription");
ListGridField unitPrice = new ListGridField("unitPrice");
items.setGridFields(itemDescription, unitPrice);
items.setGridSortField("itemDescription");
ButtonItem saveBtn = new ButtonItem("Save");
saveBtn.addClickHandler(new com.smartgwt.client.widgets.form.fields.events.ClickHandler() {
@Override
public void onClick(com.smartgwt.client.widgets.form.fields.events.ClickEvent event) {
event.getForm().saveData(new DSCallback() {
@Override
public void execute(DSResponse response, Object rawData, DSRequest request) {
Record rec = response.getData()[0];
JavaScriptObject rawItems = rec.getAttributeAsJavaScriptObject("items");
String html = StringUtil.asHTML(new JSONEncoder().encode(rawItems));
SC.say("Record saved with items:" + html);
}
});
}
});
exampleForm.setItems(orderID, orderDate, items, saveBtn);
Criteria orderCriteria = new Criteria();
orderCriteria.addCriteria("orderID", 1);
orderDS.fetchData(orderCriteria, new DSCallback() {
@Override
public void execute(DSResponse response, Object rawData, DSRequest request) {
DynamicForm exampleForm = (DynamicForm) Canvas.getById("exampleForm");
exampleForm.editRecord(response.getData()[0]);
}