Hi Isomorphic,
I have following problem with programmatically setting a date value to a non-Databound SelectItem with a valueMap (using v10.1p_2017-02-22).
No way I try I get the wanted result. For one of the cases I expect the following:
Also for the lower two SelectItems, where the "Set value" works as expected, I get "Must be a date" as validation error for "Save".
BuiltInDS.java:
Thanks you and Best regards
Blama
I have following problem with programmatically setting a date value to a non-Databound SelectItem with a valueMap (using v10.1p_2017-02-22).
No way I try I get the wanted result. For one of the cases I expect the following:
- Click "Set value".
- The correct value is selected from the valueMap (Q3/2017)
- Click "Save"
- Save succeeds.
- After window close/reopen: The correct value is selected from the valueMap and the SelectItem has exactly 4 entries (not 5)
Also for the lower two SelectItems, where the "Set value" works as expected, I get "Must be a date" as validation error for "Save".
BuiltInDS.java:
Code:
package com.smartgwt.sample.client; import java.util.Date; import java.util.LinkedHashMap; import com.google.gwt.core.client.EntryPoint; import com.smartgwt.client.Version; import com.smartgwt.client.core.KeyIdentifier; import com.smartgwt.client.data.AdvancedCriteria; import com.smartgwt.client.data.DataSource; import com.smartgwt.client.types.OperatorId; import com.smartgwt.client.util.Page; import com.smartgwt.client.util.PageKeyHandler; import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.IButton; import com.smartgwt.client.widgets.Window; 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.FormItem; import com.smartgwt.client.widgets.form.fields.SelectItem; import com.smartgwt.client.widgets.grid.ListGrid; import com.smartgwt.client.widgets.layout.VLayout; public class BuiltInDS implements EntryPoint { private VLayout mainLayout; private IButton recreateBtn; public void onModuleLoad() { KeyIdentifier debugKey = new KeyIdentifier(); debugKey.setCtrlKey(true); debugKey.setKeyName("D"); Page.registerKey(debugKey, new PageKeyHandler() { public void execute(String keyName) { SC.showConsole(); } }); mainLayout = new VLayout(20); mainLayout.setWidth100(); mainLayout.setHeight100(); recreateBtn = new IButton("Recreate"); recreateBtn.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { recreate(); } }); mainLayout.addMember(recreateBtn); recreate(); mainLayout.draw(); } private void recreate() { Window w = new Window(); w.setWidth("95%"); w.setHeight("95%"); w.setMembersMargin(0); w.setModalMaskOpacity(70); w.setTitle(" (" + Version.getVersion() + "/" + Version.getSCVersionNumber() + ")"); w.setTitle("SelectItem valueMap and setValue() problems" + w.getTitle()); w.setShowMinimizeButton(false); w.setIsModal(true); w.setShowModalMask(true); w.setAutoDraw(false); w.centerInPage(); w.addItem(getFormLayout(true, true)); w.addItem(getFormLayout(true, false)); w.addItem(getFormLayout(false, true)); w.addItem(getFormLayout(false, false)); ListGrid lg = new ListGrid(DataSource.get("supplyItem")); lg.setCanEdit(true); lg.fetchData(new AdvancedCriteria("itemID", OperatorId.EQUALS, 1484)); w.addItem(lg); w.show(); } private VLayout getFormLayout(final boolean setAsId, final boolean useStringMap) { VLayout vL = new VLayout(5); final DynamicForm df = new DynamicForm(); df.setDataSource(DataSource.get("supplyItem")); final FormItem sku = new FormItem("SKU"); final FormItem nextShipment = new SelectItem("nextShipment"); if (useStringMap) nextShipment.setValueMap(getStringValueMap()); else nextShipment.setValueMap(getDateValueMap()); df.setFields(sku, nextShipment); vL.addMember(df); df.fetchData(new AdvancedCriteria("itemID", OperatorId.EQUALS, 1484)); IButton set = new IButton("Set value", new ClickHandler() { @SuppressWarnings("deprecation") @Override public void onClick(ClickEvent event) { if (setAsId) nextShipment.setValue(new Date(117, 8, 30)); else nextShipment.setValue("Q3/2017"); } }); vL.addMember(set); IButton save = new IButton("Save", new ClickHandler() { @Override public void onClick(ClickEvent event) { df.saveData(); } }); vL.addMember(save); return vL; } private LinkedHashMap<String, String> getStringValueMap() { LinkedHashMap<String, String> vm = new LinkedHashMap<String, String>(); vm.put("03/31/2017", "Q1/2017"); vm.put("06/30/2017", "Q2/2017"); vm.put("09/30/2017", "Q3/2017"); vm.put("12/31/2017", "Q4/2017"); return vm; } @SuppressWarnings("deprecation") private LinkedHashMap<Date, String> getDateValueMap() { LinkedHashMap<Date, String> vm = new LinkedHashMap<Date, String>(); vm.put(new Date(117, 2, 31), "Q1/2017"); vm.put(new Date(117, 5, 30), "Q2/2017"); vm.put(new Date(117, 8, 30), "Q3/2017"); vm.put(new Date(117, 11, 31), "Q4/2017"); return vm; } }
Blama
Comment