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

RadioGroup WicktTester with a AjaxSubmitLink fails

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.5.0
    • Fix Version/s: 1.5.1
    • Component/s: wicket
    • Labels:
      None

      Description

      After migrating to Wicket 1.5.0 some of our WicketTester unit-tests fail, they involve a RadioGroup component with a Enum as model. The setup works correctly at runtime. The problem is as follows:

      The enum (simplified enum, for demonstration purposes): public enum ValEnum

      { VAL_A, VAL_B; }

      A form containing a RadioGroup, the individual Radio components are based on the Enum values. When submiting the form (using a AjaxSubmitLink) containing the RadioGroup in a WicktTester situation a WicketRuntimeException is thrown containing:
      org.apache.wicket.WicketRuntimeException: submitted http post value [VAL_A] for RadioGroup component [1:form:group] is illegal because it does not contain relative path to a Radio component. Due to this the RadioGroup component cannot resolve the selected Radio component pointed to by the illegal value. A possible reason is that component hierarchy changed between rendering and form submission.

      It works correctly when submitting the form using a normal SubmitLink.

      Debugging the select function of the FormTester shows te correct value being placed in the PostParameters ("radio1" is the value being set).

      1. myproject.zip
        25 kB
        Dries Schulten

        Issue Links

          Activity

          Hide
          bitstorm Andrea Del Bene added a comment -

          Ok thank you Igor!

          Show
          bitstorm Andrea Del Bene added a comment - Ok thank you Igor!
          Hide
          ivaynberg Igor Vaynberg added a comment -

          i am too working on a patch already...almost done

          Show
          ivaynberg Igor Vaynberg added a comment - i am too working on a patch already...almost done
          Hide
          bitstorm Andrea Del Bene added a comment -

          The bug is inside 'BaseWicketTester.serializeFormToRequest'. This method is called before form is submitted and checks if each form field has a corresponding post parameter. If such parameter is missing a new parameter is added and its value is get calling 'FormComponent.getValue()' .
          This method for RadioGroup returns the model value (ex: VAL_A), but should return the value of selected Radio (ex:radio4). Everything works fine if we build a FormTester because it performs the right parameters initialization inside its constructor (see form visitor).

          I'm working on a patch but it needs a little refactoring to avoid code replication.

          Show
          bitstorm Andrea Del Bene added a comment - The bug is inside 'BaseWicketTester.serializeFormToRequest'. This method is called before form is submitted and checks if each form field has a corresponding post parameter. If such parameter is missing a new parameter is added and its value is get calling 'FormComponent.getValue()' . This method for RadioGroup returns the model value (ex: VAL_A), but should return the value of selected Radio (ex:radio4). Everything works fine if we build a FormTester because it performs the right parameters initialization inside its constructor (see form visitor). I'm working on a patch but it needs a little refactoring to avoid code replication.
          Hide
          dries.schulten Dries Schulten added a comment - - edited

          My bad, the formTester.submit() step is not needed. I changed my testcase, using the WicketTester to:

          • Render the page, then using clickLink on the AjaxSubmitLink -> error
          • Render the page, create a formTester, clickLink on the AjaxSubmitLink -> pass
          • Render the page, create a formTester, select a value, clickLink on the AjaxSubmitLink -> pass

          So it seems that the error occurs when directly submitting a form using a AjaxSubmitLink without the creation of a FormTester on the form. Not sure if this is a bug then... This construction used to work in the 1.4.x versions.

          Updated test-case in the attached quickstart.

          Show
          dries.schulten Dries Schulten added a comment - - edited My bad, the formTester.submit() step is not needed. I changed my testcase, using the WicketTester to: Render the page, then using clickLink on the AjaxSubmitLink -> error Render the page, create a formTester, clickLink on the AjaxSubmitLink -> pass Render the page, create a formTester, select a value, clickLink on the AjaxSubmitLink -> pass So it seems that the error occurs when directly submitting a form using a AjaxSubmitLink without the creation of a FormTester on the form. Not sure if this is a bug then... This construction used to work in the 1.4.x versions. Updated test-case in the attached quickstart.
          Hide
          bitstorm Andrea Del Bene added a comment -

          Hi Dries,

          I've looked at your test case but I don't understand why you double submit form, once calling submit() and once clicking on submit link:

          formTester.submit();
          tester.clickLink("form:submit");

          Btw, if you invert these two line of code, test passes without any problem.

          Show
          bitstorm Andrea Del Bene added a comment - Hi Dries, I've looked at your test case but I don't understand why you double submit form, once calling submit() and once clicking on submit link: formTester.submit(); tester.clickLink("form:submit"); Btw, if you invert these two line of code, test passes without any problem.
          Hide
          dries.schulten Dries Schulten added a comment -

          See the attached quickstart, the TestHomePage class contains a unit-test showing the problem.

          Show
          dries.schulten Dries Schulten added a comment - See the attached quickstart, the TestHomePage class contains a unit-test showing the problem.
          Hide
          mgrigorov Martin Grigorov added a comment -

          Please attach a test case. Thanks!

          Show
          mgrigorov Martin Grigorov added a comment - Please attach a test case. Thanks!
          Hide
          dries.schulten Dries Schulten added a comment -

          Attaching 1.5.0 quickstart showing the problem.

          Show
          dries.schulten Dries Schulten added a comment - Attaching 1.5.0 quickstart showing the problem.

            People

            • Assignee:
              ivaynberg Igor Vaynberg
              Reporter:
              dries.schulten Dries Schulten
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development