Announcement

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

    FilterBuilder doesn't display restored datetime field values when archived using AdvancedCriteria's toJSON() & from JSON() archiving methods

    I'm using SmartClient Version: v11.1p_2017-08-08/PowerEdition Deployment (built 2017-08-08)

    My application allows a user to build a filter for creating reports. The filterBuilder's criteria is archived in a database for each report. I use myStr = filterBuilder.getCriteria.toJSON() to archive and filterBuilder.setCriteria(AcvancedCriteria.fromJSON(myStr)) to restore. For DataSource date fields (i.e. type="datetime"), when the FilterBuilder's criteria is restored , it does not always display the underlying value. It seems to fail for date values chosen by the date choose. i.e. operator is "less than" and the value is "01/03/2018". If a relative date like "Today" was picked, all works as expected.

    This can easily be seen by adding the following debug code to the Adv. Filter Builder showcase and experimenting with the Nationhood field.

    Code:
     
            /*
             *  debug code.  Add two FilterBuilders.  One that gets the configured filterBuilder criteria directly and one that
             *  get's a copy that has been converted to a JSON string and back.
             *  An HTML flow is added to observer the JSON conversion, and an execute button to kick off the process.
             */
    
            final HTMLFlow observeCriteriaHTMLFlow = new HTMLFlow();
            observeCriteriaHTMLFlow.setWidth100();
            observeCriteriaHTMLFlow.setHeight(100);
    
            final Label directLabel = new Label("Direct:");
            directLabel.setHeight(15);
    
            final FilterBuilder directFilterBuilder = new FilterBuilder();
            directFilterBuilder.setDataSource(worldDS);
    
            final Label restoreLabel = new Label("JSON Archive/Restore:");
            restoreLabel.setHeight(15);
    
            final FilterBuilder restoreFilterBuilder = new FilterBuilder();
            restoreFilterBuilder.setDataSource(worldDS);
    
            IButton archiveButton = new IButton("Execute Direct & JSON Archive/Restore");
            archiveButton.setWidth(300);
            archiveButton.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {
    
                    // transfer criteria directly from one filterBuilder to the other
                    directFilterBuilder.setCriteria(filterBuilder.getCriteria());
    
                    // simulate an archive to database and restore to FilterBuilder
                    String criteriaStr = filterBuilder.getCriteria().toJSON();
                    observeCriteriaHTMLFlow.setContents(criteriaStr);
                    AdvancedCriteria criteria =  AdvancedCriteria.fromJSON(criteriaStr);
                    restoreFilterBuilder.setCriteria(criteria);
                }
            });
    
            vStack.addMember(observeCriteriaHTMLFlow);
            vStack.addMember(archiveButton);
            vStack.addMember(directLabel);
            vStack.addMember(directFilterBuilder);
            vStack.addMember(restoreLabel);
            vStack.addMember(restoreFilterBuilder);

    P.S. This may be something for a separate thread, but when selecting Nationhood, the filterBuider's default is to choose the operator equals and a dual date picker with From and To fields. If you toggle to any other operator and then back to equals, the date chooser becomes a single date input, not a bounded date input. A bounding option would be more intuitive and easier to read for my users than needing to add separate less than and greater than criteria. In this case, when either using the direct criteria initialization method or by saving and restoring through JSON, the displaying filterBuilder fails to show the bounded dates chosen.





    #2
    See JSONEncoder docs: there is a specific mode designed to allow round-tripping of date and datetime values, which isn't something built into JSON, which is why just calling toJSON() won't work. This is also covered in the AdvancedCriteria class overview doc.

    Comment


      #3
      Thanks, that led to being able to encode the entire criteria like so.

      Code:
              JSONEncoder encoder = new JSONEncoder();
              encoder.setDateFormat(JSONDateFormat.DATE_CONSTRUCTOR);
              String criteriaStr = encoder.encode(myFilterBuilder.getCriteria());
      .

      Comment

      Working...
      X