Here:

/**
 * Submits form without validating it.
 *
 * @author Martin
 */
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) {
    HttpServletRequest httpServletRequest = ((WebRequest) getComponent()
        .getRequest()).getHttpServletRequest();

    Map parameters;

    if (httpServletRequest instanceof MockHttpServletRequest) {
      parameters = ((MockHttpServletRequest)
httpServletRequest).getParameterMap();
    } else {
      parameters = ((org.mortbay.jetty.Request)
httpServletRequest).getParameters();
    }

    parameters.put(getHiddenFieldId(getForm()),
getComponent().urlFor(IOnChangeListener.INTERFACE));

    final FormComponent<?> formComponent = (FormComponent<?>) getComponent();

    try {
      if (isUpdateModel()) {
        formComponent.inputChanged();
        formComponent.validate();

        if (!formComponent.hasErrorMessage()) {
          formComponent.valid();
          formComponent.updateModel();
        }
      }

      super.onEvent(target);
    } catch (RuntimeException e) {
      Utils.errorLog(AjaxFormSubmittingChangeListenerBehavior.class, e);
      onError(target);
    }
  }

  /**
   * @return boolean
   */
  protected boolean isUpdateModel() {
    return true;
  }

  /**
   * @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);
    }
  }
}

2010/4/23 Joseph Pachod <[email protected]>:
> Igor Vaynberg wrote:
>>
>> there is ajaxformsubmitting behavior which will update the entire form
>>
>> -igor
>>
>
> thanks
>
> however, that's not exactly my need, being just recording the user input
> (not to loose it) without validating. Is there no way around, like a hook
> from Ajax to act only on some component internal state ?
>
> My use case being the following:
>
>> The use case for it is a ListView with reuseItems(true) which loses in
>> transit state. In more details, it means the user writes something in one
>> of
>> the listitem's textfield, then click on "add new item" => I want the
>> textfield's state to be known and preserved, whereas the whole form
>> shouldn't be submitted yet.
>
> which approach would you recommend ?
>
> thanks again
>
> joseph
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to