Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-2104

FormTester does not toggle selected values when using selectMultiple

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.3.5
    • 1.4-RC3
    • wicket
    • None
    • Ubuntu 8.04, Java 1.6

    Description

      FormTester.selectMultiple only appends values, there is no way to replace or 'uncheck' items in a multiple select. This is contrary to the documentation in the source which does mention a toggle.
      This is different from issue WICKET-1893. The solution there affects the model prior to submit().

      Following are three methods that could be added to implement the toggle capability:
      add to inner class
      protected abstract class ChoiceSelector :

      /**

      • Implements removal of current selection(s) to allow toggle behaviour of assignValueToFormComponent.
      • @param formComponent
      • a <code>FormComponent</code>
        */
        protected void doUnSelect() // should this be final? { // multiple selectable should remove unselected option(s) removeFormComponentValues(formComponent); }

      add to FormTester

      /**

      • Simulates selecting multiple options for the <code>FormComponent</code>. The
      • method only support multiple selectable <code>FormComponent</code>s.
      • @see #select(String, int)
      • @param formComponentId
      • relative path (from <code>Form</code>) to the selectable
      • <code>FormComponent</code>
      • @param indexes
      • index of the selectable option, starting from 0
      • @param toggle
      • set to <code>true</code> to clear existing selected option(s)
      • set to <code>false</code> to append to existing selected option(s)
        */
        public void selectMultiple(String formComponentId, int[] indexes, boolean toggle)
        {
        checkClosed();

      ChoiceSelector choiceSelector = choiceSelectorFactory.createForMultiple((FormComponent)workingForm.get(formComponentId));

      if (toggle)

      { choiceSelector.doUnSelect(); }

      selectMultiple(formComponentId, indexes);
      }

      add to FormTester

      /**

      • Removes <code>FormComponent</code>'s values from request parameter.
      • @param formComponent
      • a <code>FormComponent</code>
        */
        private void removeFormComponentValues(FormComponent formComponent)
        Unknown macro: { if (parameterExist(formComponent)) { Map newParameters = new HashMap(); // could also get parameters from request and clear() newParameters.put(formComponent.getInputName(), new String[0]); baseWicketTester.getServletRequest().setParameters(newParameters); } }

      Attachments

        Activity

          People

            jdonnerstag Juegen Donnerstag
            ray_bon@telus.net ray bon
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: