No announcement yet.
  • 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


    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


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

    Is there not a


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

    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


      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.


        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.