Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    is DateTimeItem.setDisplayFormat(DateDisplayFormat.TODATESTAMP) supported?

    Hello,

    we're trying to use DateTimeItem with text field and we have to use Zulu format for both user input and storing the datetime in the database (as text). DateDisplayFormat.TODATESTAMP looks very close, but it doesn't seem to work for us. DateTimeItem forms a correct text representation when using its picker, but submit fails validation saying "Must be a Date". Is this format supported or we need to provide a custom formatter?
    we're using SmartGWT 6.0/SmartClient Version: v11.0p_2017-04-06/Enterprise Deployment (built 2017-04-06)

    #2
    It sounds like the field in your DataSource is declared as a date or datetime field, rather than a text type.

    If that's not it, please show your DS and the client-side code that builds the DateTimeItem.

    Comment


      #3
      We ended up using datetime column in the database and added a FormItemValueParser because DateParser wasn't get called for some reason as a short term solution. The following code illustrates the issue. Simply select Office Supplies on the right hand side, click on any row in the middle grid, use picker to set date/time and click save at the top of the screen. It fails the client side validation for us. Everything works once FormItemValueParser is in place.

      Code:
      package com.smartgwt.sample.client;
      
      import java.util.Date;
      
      import com.google.gwt.core.client.EntryPoint;
      import com.google.gwt.i18n.client.DateTimeFormat;
      import com.smartgwt.client.core.KeyIdentifier;
      import com.smartgwt.client.data.DSCallback;
      import com.smartgwt.client.data.DSRequest;
      import com.smartgwt.client.data.DSResponse;
      import com.smartgwt.client.data.DataSource;
      import com.smartgwt.client.data.Record;
      import com.smartgwt.client.types.DateDisplayFormat;
      import com.smartgwt.client.types.SelectionStyle;
      import com.smartgwt.client.types.SortArrow;
      import com.smartgwt.client.util.PageKeyHandler;
      import com.smartgwt.client.util.DateDisplayFormatter;
      import com.smartgwt.client.util.DateInputFormatter;
      import com.smartgwt.client.util.DateParser;
      import com.smartgwt.client.util.DateUtil;
      import com.smartgwt.client.util.Page;
      import com.smartgwt.client.util.SC;
      import com.smartgwt.client.widgets.Button;
      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.DateTimeItem;
      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.grid.events.RecordClickEvent;
      import com.smartgwt.client.widgets.grid.events.RecordClickHandler;
      import com.smartgwt.client.widgets.layout.HLayout;
      import com.smartgwt.client.widgets.layout.VStack;
      import com.smartgwt.client.widgets.viewer.DetailViewer;
      
      /**
       * Entry point classes define <code>onModuleLoad()</code>.
       */
      public class BuiltInDS implements EntryPoint {
          private ListGrid boundList;
          private DynamicForm boundForm;
          private IButton saveBtn;
          private DetailViewer boundViewer;
          private IButton newBtn;
      
          /**
           * This is the entry point method.
           */
          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();
                  }
              });
      
      
              ListGrid grid = new ListGrid();
              grid.setLeft(20);
              grid.setTop(75);
              grid.setWidth(130);
              grid.setLeaveScrollbarGap(false);
              grid.setShowSortArrow(SortArrow.NONE);
              grid.setCanSort(false);
              grid.setFields(new ListGridField("dsTitle", "Select a DataSource"));
              grid.setData(new ListGridRecord[]{
                      new DSRecord("Animals", "animals"),
                      new DSRecord("Office Supplies", "supplyItem"),
                      new DSRecord("Employees", "employees")}
              );
              grid.setSelectionType(SelectionStyle.SINGLE);
              grid.addRecordClickHandler(new RecordClickHandler() {
                  public void onRecordClick(RecordClickEvent event) {
                      DSRecord record = (DSRecord) event.getRecord();
                      bindComponents(record.getDsName());
                  }
              });
      
              grid.draw();
      
              VStack vStack = new VStack();
              vStack.setLeft(175);
              vStack.setTop(75);
              vStack.setWidth("70%");
              vStack.setMembersMargin(20);
              
              DynamicForm form = new DynamicForm();
              form.setDataSource("supplyItem");
              DateTimeItem date = new DateTimeItem("nextShipment");
              // this works
      /*        date.setEditorValueParser((value, form1, item) -> {
                  SC.logWarn("Parsing value " + value);
                  if (value != null) {
                      final DateTimeFormat format = DateTimeFormat.getFormat("yyyyMMddTHHmmssZ");
                         Date date1 = format.parse(value);
                         return date1;
                  }
                  return null;
              });*/
              date.setDisplayFormat(DateDisplayFormat.TODATESTAMP);
       //       DateUtil.setShortDatetimeDisplayFormatter(DateUtil.TODATESTAMP);
              // this never gets called
       /*       DateUtil.setDateParser(new DateParser() {
                  public Date parse(String dateString) {
                      SC.logWarn("Parsing " + dateString);
                     final DateTimeFormat format = DateTimeFormat.getFormat("yyyyMMddTHHmmssZ");
                     Date date = format.parse(dateString);
                     return date;
                  }
               });*/
      //        date.setInputFormat("YMD");
              form.setItems(date);
              vStack.addMember(form);
              IButton save = new IButton("Save", new ClickHandler() {
                  
                  @Override
                  public void onClick(ClickEvent event) {
                      form.saveData();
                  }
              });
              vStack.addMember(save);
      
              Label label = new Label();
              label.setContents("<ul>" +
                      "<li>select a datasource from the list at left to bind to these components</li>" +
                      "<li>click a record in the grid to view and edit that record in the form</li>" +
                      "<li>click <b>New</b> to start editing a new record in the form</li>" +
                      "<li>click <b>Save</b> to save changes to a new or edited record in the form</li>" +
                      "<li>click <b>Clear</b> to clear all fields in the form</li>" +
                      "<li>click <b>Filter</b> to filter (substring match) the grid based on form values</li>" +
                      "<li>click <b>Fetch</b> to fetch records (exact match) for the grid based on form values</li>" +
                      "<li>double-click a record in the grid to edit inline (press Return, or arrow/tab to another record, to save)</li>" +
                      "</ul>");
              vStack.addMember(label);
      
              boundList = new ListGrid();
              boundList.setHeight(200);
              boundList.setCanEdit(true);
      
              boundList.addRecordClickHandler(new RecordClickHandler() {
                  public void onRecordClick(RecordClickEvent event) {
                      Record record = event.getRecord();
                      form.editSelectedData(boundList);
                      boundForm.editRecord(record);
                      saveBtn.enable();
                      boundViewer.viewSelectedData(boundList);
                  }
              });
              vStack.addMember(boundList);
      
              boundForm = new DynamicForm();
              boundForm.setNumCols(6);
              boundForm.setAutoFocus(false);
              vStack.addMember(boundForm);
      
              HLayout hLayout = new HLayout(10);
              hLayout.setMembersMargin(10);
              hLayout.setHeight(22);
      
              saveBtn = new IButton("Save");
              saveBtn.addClickHandler(new ClickHandler() {
                  public void onClick(ClickEvent event) {
                      boundForm.saveData();
                      if (!boundForm.hasErrors()) {
                          boundForm.clearValues();
                          saveBtn.disable();
                      }
                  }
              });
              hLayout.addMember(saveBtn);
      
              newBtn = new IButton("New");
              newBtn.addClickHandler(new ClickHandler() {
                  public void onClick(ClickEvent event) {
                      boundForm.editNewRecord();
                      saveBtn.enable();
                  }
              });
              hLayout.addMember(newBtn);
      
              IButton clearBtn = new IButton("Clear");
              clearBtn.addClickHandler(new ClickHandler() {
                  public void onClick(ClickEvent event) {
                      boundForm.clearValues();
                      saveBtn.disable();
                  }
              });
              hLayout.addMember(clearBtn);
      
              IButton filterBtn = new IButton("Filter");
              filterBtn.addClickHandler(new ClickHandler() {
                  public void onClick(ClickEvent event) {
                      boundList.filterData(boundForm.getValuesAsCriteria());
                      saveBtn.disable();
                  }
              });
              hLayout.addMember(filterBtn);
      
              IButton fetchBtn = new IButton("Fetch");
              fetchBtn.addClickHandler(new ClickHandler() {
                  public void onClick(ClickEvent event) {
                      boundList.fetchData(boundForm.getValuesAsCriteria());
                      saveBtn.disable();
                  }
              });
              hLayout.addMember(fetchBtn);
      
              vStack.addMember(hLayout);
      
              boundViewer = new DetailViewer();
              vStack.addMember(boundViewer);
      
              vStack.draw();
          }
      
          private void bindComponents(String dsName) {
              DataSource ds = DataSource.get(dsName);
              boundList.setDataSource(ds);
              boundViewer.setDataSource(ds);
              boundForm.setDataSource(ds);
              boundList.fetchData();
              newBtn.enable();
              saveBtn.disable();
          }
      }
      SupplyItem.ds.xml:
      Code:
       <DataSource
            ID="supplyItem"
            serverType="sql"
            tableName="supplyItem"
            titleField="itemName"
            testFileName="/examples/shared/ds/test_data/supplyItem.data.xml"
            dbImportFileName="/examples/shared/ds/test_data/supplyItemLarge.data.xml"
        >
            <fields>
                <field name="itemID"      type="sequence" hidden="false"       primaryKey="true"/>
                <field name="itemName"    type="text"     title="Item"        length="128"       required="true"/>
                <field name="SKU"         type="text"     title="SKU"         length="10"        required="true"/>
                <field name="description" type="text"     title="Description" length="2000"/>
                <field name="category"    type="text"     title="Category"    length="128"       required="true"
                       foreignKey="supplyCategory.categoryName"/>
                <field name="units"       type="enum"     title="Units"       length="5">
                    <valueMap>
                        <value>Roll</value>
                        <value>[U]Ea[/U]</value>
                        <value>[U]Pkt[/U]</value>
                        <value>Set</value>
                        <value>Tube</value>
                        <value>Pad</value>
                        <value>Ream</value>
                        <value>Tin</value>
                        <value>Bag</value>
                        <value>[U]Ctn[/U]</value>
                        <value>Box</value>
                    </valueMap>
                </field>
                <field name="unitCost"    type="float"    title="Unit Cost"   required="true">
                    <validators>
                        <validator type="floatRange" min="0" errorMessage="Please enter a valid (positive) cost"/>
                        <validator type="floatPrecision" precision="2" errorMessage="The maximum allowed precision is 2"/>
                    </validators>
                </field>
                <field name="inStock"   type="boolean"  title="In Stock"/>
                <field name="nextShipment"  type="datetime" title="Next Shipment"/>
            </fields>
        </DataSource>
      and isomorphic.script was modified to use datetime column type.
      Last edited by abthere; 17 Jul 2017, 07:58.

      Comment

      Working...
      X