You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Martin Grigorov (JIRA)" <ji...@apache.org> on 2010/12/27 14:57:47 UTC

[jira] Assigned: (WICKET-1732) FormTester's DropDownChoice onSelectionChanged() behaviour doesn't reload page

     [ https://issues.apache.org/jira/browse/WICKET-1732?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Martin Grigorov reassigned WICKET-1732:
---------------------------------------

    Assignee: Martin Grigorov

> FormTester's DropDownChoice onSelectionChanged() behaviour doesn't reload page
> ------------------------------------------------------------------------------
>
>                 Key: WICKET-1732
>                 URL: https://issues.apache.org/jira/browse/WICKET-1732
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 1.3.0-final, 1.3.3
>            Reporter: David Shepherdson
>            Assignee: Martin Grigorov
>            Priority: Minor
>
> When a DropDownChoice's onSelectionChanged() notification is sent from a browser, it causes the whole page to be reloaded/redisplayed (because the form is submitted). However, when the same notification is sent through the FormTester, it doesn't submit the form and therefore other components on the page may not be updated/redisplayed.
> We're working around this by overriding FormTester's select() method so that it submits the form as follows:
>     @Override
>     public void select(String formComponentId, int index) {
>         super.select(formComponentId, index);
>         
>         // Workaround for Wicket FormTester bug: selection changed notifications cause the page
>         // to be reloaded in a real browser, but they don't when using the Wicket tester.
>         FormComponent component = (FormComponent)getForm().get(formComponentId);
>         if (component instanceof DropDownChoice) {
>             try
>             {
>                 Method wantOnSelectionChangedNotificationsMethod = DropDownChoice.class.getDeclaredMethod("wantOnSelectionChangedNotifications", new Class[0]);
>                 wantOnSelectionChangedNotificationsMethod.setAccessible(true);
>                 boolean wantOnSelectionChangedNotifications = ((Boolean)wantOnSelectionChangedNotificationsMethod.invoke(component, new Object[0])).booleanValue();
>                 if (wantOnSelectionChangedNotifications) {
>                     // Notification method call has already been made by super,
>                     // but we want to trigger the page load, as would happen in a real browser.
>                     
>                     // First, use reflection to get the form's hidden field id.
>                     Method getHiddenFieldIdMethod = Form.class.getDeclaredMethod("getHiddenFieldId");
>                     getHiddenFieldIdMethod.setAccessible(true);
>                     String hiddenFieldId = (String) getHiddenFieldIdMethod.invoke(getForm());
>                     
>                     // Now set the parameter in the form
>                     // to cause it to call the callback when submitted.
>                     m_wicketTester.getServletRequest().setParameter(
>                             hiddenFieldId, component.urlFor(IOnChangeListener.INTERFACE).toString());
>                     
>                     // And finally submit the form.
>                     submit();
>                     
>                 }
>             }
>             catch (Exception e)
>             {
>                 throw new RuntimeException(e);
>             }
>         }
>     }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.