Wicket
  1. Wicket
  2. WICKET-4730

Filter component does not clear filter fields

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 6.0.0-beta3
    • Fix Version/s: 6.1.0
    • Component/s: wicket-extensions
    • Labels:
      None

      Description

      The GoAndClearFilter.onClearSubmit() does not clear filter fields because the originalState member has the current values of the filter. I think it should create a new instance of the originalState class instead of clone the model.

      To verify use the phonebook sample (https://github.com/wicketstuff/core/tree/master/jdk-1.6-parent/phonebook). The clear only works if "go" was not pressed after enter some values in the filter, but if you press go and then want to clear the filter it keeps the values.

      Attached is a patch that makes the phonebook sample work.

      It might also be useful if the originalState attribute were made protected or accessible via protected method to allow users to overwrite the onClearSubmit() method and access the originalState attribute.

      1. commit-347c459
        1 kB
        Andreas Kuhtz

        Activity

        Hide
        Andreas Kuhtz added a comment -

        Apologies for the late response (due to holidays) ... Thanks for the explanation and the fix!

        Show
        Andreas Kuhtz added a comment - Apologies for the late response (due to holidays) ... Thanks for the explanation and the fix!
        Hide
        Martin Grigorov added a comment -

        Fixed it by adding an additional constructor where you can pass your own instance for original state.
        The old constructors still use the form's model object as original state.

        Show
        Martin Grigorov added a comment - Fixed it by adding an additional constructor where you can pass your own instance for original state. The old constructors still use the form's model object as original state.
        Hide
        Martin Grigorov added a comment -

        I think the problem is in wicket.contrib.phonebook.web.page.ListContactsPage#createActionsColumn().
        GoAndClearFilter properly clones the initial state and then reused it. But ListContactsPage recreates the whole filter again and again for each render and the form's model object could change at any time. If the filter is cached after the first creation then it works.

        You patch wont work for model objects which have no default constructor. And empty state doesn't always mean "initial" state.

        Show
        Martin Grigorov added a comment - I think the problem is in wicket.contrib.phonebook.web.page.ListContactsPage#createActionsColumn(). GoAndClearFilter properly clones the initial state and then reused it. But ListContactsPage recreates the whole filter again and again for each render and the form's model object could change at any time. If the filter is cached after the first creation then it works. You patch wont work for model objects which have no default constructor. And empty state doesn't always mean "initial" state.

          People

          • Assignee:
            Martin Grigorov
            Reporter:
            Andreas Kuhtz
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development