WicketTester doesn't include form submitting component id in form submissions
-----------------------------------------------------------------------------

                 Key: WICKET-1733
                 URL: https://issues.apache.org/jira/browse/WICKET-1733
             Project: Wicket
          Issue Type: Bug
          Components: wicket
    Affects Versions: 1.3.3
            Reporter: David Shepherdson
            Priority: Minor


When submitting a form with an AJAX link (or other AJAX-based control), 
WicketTester doesn't include the id of the component that 'submitted' the form, 
meaning that in situations with nested forms, the wrong form's onSubmit() 
method may be called.

We're working around this problem by overriding the clickLink() and 
executeAjaxEvent() methods as follows:

    @Override
    public void clickLink(String path, boolean isAjax) {
        Component linkComponent = getComponentFromLastRenderedPage(path);
        if (linkComponent instanceof AjaxSubmitLink) {
            AjaxSubmitLink link = (AjaxSubmitLink) linkComponent;
            Map<String, Object> requestParams = getParametersForNextRequest();
            requestParams.put(link.getInputName(), "x");
        }
        super.clickLink(path, isAjax);
    }

    @Override
    public void executeAjaxEvent(Component component, String event) {
        // Code borrowed from BaseWicketTester.

        // Run through all the behavior and select the LAST ADDED behavior which
        // matches the event parameter.
        AjaxEventBehavior ajaxEventBehavior = null;
        List behaviors = component.getBehaviors();
        for (Iterator iter = behaviors.iterator(); iter.hasNext();) {
            IBehavior behavior = (IBehavior) iter.next();

            // AjaxEventBehavior is the one to look for
            if (behavior instanceof AjaxEventBehavior) {
                AjaxEventBehavior tmp = (AjaxEventBehavior) behavior;

                if (event.equals(tmp.getEvent())) {
                    ajaxEventBehavior = tmp;
                }
            }
        }

        // Workaround: If the behaviour is an AjaxFormSubmitBehavior then add 
the
        // component's input name.
        if (ajaxEventBehavior instanceof AjaxFormSubmitBehavior
                && component instanceof FormComponent) {
            String inputName = ((FormComponent) component).getInputName();
            Map<String, Object> requestParams = getParametersForNextRequest();
            requestParams.put(inputName, "x");
        }

        super.executeAjaxEvent(component, event);
    }



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

Reply via email to