Allow Ajax FormSubmitting component without default form processing (i.e., 
analogous to IOnChangeListener)
----------------------------------------------------------------------------------------------------------

                 Key: WICKET-2562
                 URL: https://issues.apache.org/jira/browse/WICKET-2562
             Project: Wicket
          Issue Type: Improvement
          Components: wicket
    Affects Versions: 1.4.3
            Reporter: Martin Makundi
            Priority: Minor


Workaround exists but it is a reflection hack:

public abstract class AjaxFormSubmittingChangeListenerBehavior extends
    AjaxFormSubmitBehavior {
  private final static Method hiddenFieldGetter;
  static {
    try {
      hiddenFieldGetter = Form.class.getDeclaredMethod("getHiddenFieldId");
      hiddenFieldGetter.setAccessible(true);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
  
  /**
   * @see org.apache.wicket.ajax.AbstractDefaultAjaxBehavior#onBind()
   */
  @Override
  protected void onBind() {
    super.onBind();

    if (!(getComponent() instanceof IOnChangeListener))
    {
      throw new WicketRuntimeException("Behavior " + getClass().getName() +
        " can only be added to an instance of a IOnChangeListener");
    }
  }

  /**
   * @param event
   */
  public AjaxFormSubmittingChangeListenerBehavior(String event) {
    super(event);
  }

  /**
   * @see 
org.apache.wicket.ajax.form.AjaxFormSubmitBehavior#onError(org.apache.wicket.ajax.AjaxRequestTarget)
   */
  @Override
  protected void onError(AjaxRequestTarget target) {
    onSubmit(target);
  }

  /**
   * @see 
org.apache.wicket.ajax.form.AjaxFormSubmitBehavior#onEvent(org.apache.wicket.ajax.AjaxRequestTarget)
   */
  @Override
  protected void onEvent(AjaxRequestTarget target) {
    org.mortbay.util.MultiMap parameters = ((org.mortbay.jetty.Request) 
((WebRequest) getComponent()
        .getRequest()).getHttpServletRequest()).getParameters();
    parameters.put(getHiddenFieldId(getForm()), 
getComponent().urlFor(IOnChangeListener.INTERFACE));
    super.onEvent(target);
  }

  /**
   * @param form
   * @return String
   */
  private String getHiddenFieldId(Form<?> form) {
    try {
      Form<?> root = form.getRootForm();
      return (String) hiddenFieldGetter.invoke(root);
    } 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.

Reply via email to