Hi,

I'm going to write a blog article about Form component's input vs. model.
I've been asked few times about this last two weeks by colleagues of mine.
It would be good to have it in the official guide though (
https://issues.apache.org/jira/browse/WICKET-5321).

To reset a form you should:
1) use a button with default processing == false, to prevent form
validation (or just AjaxLink)
2) call form.clearInput()
3) and to set the "default" model for each form component.  Each
application should know what "default" means for its form components.


On Mon, Sep 30, 2013 at 3:46 PM, Richard W. Adams <rwada...@up.com> wrote:

> We're having trouble making our form reset button work. It's defined
> thusly:
>
> AjaxButton button = new AjaxButton("reset-button");
> ...
> <input type="button"  value="Reset"  wicket:id="reset-button" />
> _____________________________________________
>
> Here's our reset code, executed when the button is clicked. The main form
> seems to re-render OK, but a
> FormComponentPanel that is part of the form does not. I see a lot of
> discussion on Wicket form resets on the Web, but most is several years
> old. Is there an "officially" endorsed pattern or example for doing Ajax
> form resets?
> _____________________________________________
>
> public void onReset(final AjaxRequestTarget target) {
>
>         final Component.IVisitor<FormComponent<?>> visitor = new
> Component.IVisitor<FormComponent<?>>() {
>
>                 @Override public Object component(final FormComponent<?>
> formComponent) {
>
>                         if (formComponent.getDefaultModel() != null) {
> // Must have a model for the component
>                                 final Object currentValue =
> formComponent.getDefaultModelObject();  // Save model value
>                                 formComponent.clearInput();             //
> Clear out
>  formComponent.setDefaultModelObject(currentValue); // Add the value back
>                          }
>                         if (target != null) {
>                                 target.addComponent(formComponent);
>                         }
>                         return Component.IVisitor.CONTINUE_TRAVERSAL;
>                 }
>         };
>         visitChildren(FormComponent.class, visitor);


> }
>
>
> **
>
> This email and any attachments may contain information that is
> confidential and/or privileged for the sole use of the intended recipient.
>  Any use, review, disclosure, copying, distribution or reliance by others,
> and any forwarding of this email or its contents, without the express
> permission of the sender is strictly prohibited by law.  If you are not the
> intended recipient, please contact the sender immediately, delete the
> e-mail and destroy all copies.
> **
>

Reply via email to