smartGWT dome add data
程序员文章站
2024-01-26 08:58:52
...
1.页面
2.数据交互
p
/*
* Smart GWT (GWT for SmartClient)
* Copyright 2008 and beyond, Isomorphic Software, Inc.
*
* Smart GWT is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3
* as published by the Free Software Foundation. Smart GWT is also
* available under typical commercial license terms - see
* http://smartclient.com/license
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*/
import com.smartgwt.client.data.DataSource;
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.grid.ListGrid;
import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.sample.showcase.client.data.ItemSupplyLocalDS;
public class GridFormAddSample implements EntryPoint {
public void onModuleLoad() {
VLayout layout = new VLayout(15);
Label label = new Label();
label.setHeight(10);
label.setWidth100();
label.setContents("Showing items in Category 'Rollfix Glue");
layout.addMember(label);
final DataSource dataSource = ItemSupplyLocalDS.getInstance();
ListGrid listGrid = new ListGrid();
listGrid.setWidth100();
listGrid.setHeight(200);
listGrid.setDataSource(dataSource);
listGrid.setAutoFetchData(true);
layout.addMember(listGrid);
final DynamicForm form = new DynamicForm();
form.setNumCols(4);
form.setDataSource(dataSource);
form.setValue("category", "Rollfix Glue");
form.setValue("itemName", "[Enter Item Name]");
form.setValue("SKU", "[SKU]");
form.setValue("unitCoset", "[Enter Price]");
layout.addMember(form);
IButton button = new IButton("Save New");
button.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
form.saveData();
form.reset();
}
});
layout.addMember(button);
layout.draw();
}
}
2.数据交互
p
ackage com.smartgwt.sample.showcase.client.data;
import com.smartgwt.client.data.DSRequest;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.fields.*;
import com.smartgwt.client.widgets.form.validator.FloatPrecisionValidator;
import com.smartgwt.client.widgets.form.validator.FloatRangeValidator;
public class ItemSupplyLocalDS extends DataSource {
private static ItemSupplyLocalDS instance = null;
public static ItemSupplyLocalDS getInstance() {
if (instance == null) {
instance = new ItemSupplyLocalDS("supplyItemLocalDS");
}
return instance;
}
public ItemSupplyLocalDS(String id) {
setID(id);
DataSourceIntegerField pkField = new DataSourceIntegerField("itemID");
pkField.setHidden(true);
pkField.setPrimaryKey(true);
DataSourceTextField itemNameField = new DataSourceTextField("itemName", "Item Name", 128, true);
DataSourceTextField skuField = new DataSourceTextField("SKU", "SKU", 10, true);
DataSourceTextField descriptionField = new DataSourceTextField("description", "Description", 2000);
DataSourceTextField categoryField = new DataSourceTextField("category", "Category", 128, true);
categoryField.setForeignKey("supplyCategory.categoryName");
DataSourceEnumField unitsField = new DataSourceEnumField("units", "Units", 5);
unitsField.setValueMap("Roll", "Ea", "Pkt", "Set", "Tube", "Pad", "Ream", "Tin", "Bag", "Ctn", "Box");
DataSourceFloatField unitCostField = new DataSourceFloatField("unitCost", "Unit Cost", 5);
FloatRangeValidator rangeValidator = new FloatRangeValidator();
rangeValidator.setMin(0);
rangeValidator.setErrorMessage("Please enter a valid (positive) cost");
FloatPrecisionValidator precisionValidator = new FloatPrecisionValidator();
precisionValidator.setPrecision(2);
precisionValidator.setErrorMessage("The maximum allowed precision is 2");
unitCostField.setValidators(rangeValidator, precisionValidator);
DataSourceBooleanField inStockField = new DataSourceBooleanField("inStock", "In Stock");
DataSourceDateField nextShipmentField = new DataSourceDateField("nextShipment", "Next Shipment");
setFields(pkField, itemNameField, skuField, descriptionField, categoryField, unitsField,
unitCostField, inStockField, nextShipmentField);
setClientOnly(true);
setTestData(ItemData.getRecords());
}
protected Object transformRequest(DSRequest dsRequest) {
return super.transformRequest(dsRequest);
}
}
推荐阅读
-
smartGWT dome add data
-
smartGWT dome form Validator
-
excel操作之Add Data to a Spreadsheet Cell_javascript技巧
-
MySQL的Data_ADD函数与日期格式化函数说明
-
MySQL的Data_ADD函数与日期格式化函数说明
-
excel操作之Add Data to a Spreadsheet Cell_javascript技巧
-
【leetcode】211. Add and Search Word - Data structure design
-
LeetCode-211. Add and Search Word - Data structure design(字典树和递归)
-
【Leetcode&C语言&Tire】208.Implement Trie (Prefix Tree) & 211.Design Add and Search Words Data Structure
-
211. Add and Search Word - Data structure design(难啊)