[
https://issues.apache.org/jira/browse/WICKET-1732?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12912735#action_12912735
]
Peter Ertl commented on WICKET-1732:
------------------------------------
Is this issue still existant in 1.4 or 1.5? 1.3 is not maintained anymore.
> 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
> 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.