Announcement

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

    Filter Builder. How to detect that the Filter is Cleared or Empty.

    I want to detect, from a FilterBuilder object, that it's criteria is in the cleared or not initialized state. How do I do that?

    Initially the Filter is cleared with

    filterBuilder.clearCriteria();

    In some other click handler I want to detect if the Filter Builder is still empty or cleared state.

    Do I have to write code

    filterBuilder.getCriteria(false)

    and then test that the component Criterion has a null value?

    Is there not a

    filterBuilder.getClearState()

    call? True if clear, false if set? Or is this onus on me?

    #2
    Is there an easier way - an existing method - than this?

    AdvancedCriteria crit = filterBuilder.getCriteria();
    boolean isCleared = false;
    try {
    if ( crit.getCriteria()[0] == null ) {
    isCleared = true;
    }
    catch (Exception e) {
    isCleared = true;
    }

    if ( isCleared ) {
    do this
    }
    else {
    do that
    }

    Comment


      #3
      That's not very long (and it's not clear why you have exception handling), but if you want something even shorter, you could use DataSource.compareCriteria() to compare to a known empty criteria.

      Comment


        #4
        Agreed. But still think you might add a method to FilterBuilder, when filterBulder.setAllowEmpty(true), that returns a boolean indicating if the builder is in cleared state or not. And I suppose do the correct thing when setAllowEmpty(false).

        Experience has shown that checking for null cases is more rigorous between SmartGWT releases by wrapping the check with the exception handler.

        Comment

        Working...
        X