You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Jeremy Thomerson <je...@wickettraining.com> on 2010/04/29 01:36:55 UTC
Re: AjaxFormComponentUpdatingBehavior breaking wicket's convention ?
Which alternatives then?
I'm not sure I understand what your problem with this component is. The
component is designed to mimic the entire submit process for a single
component. It says this in the javadoc: "This behavior encapsulates the
entire form-processing workflow as relevant only to this component". It
also warns you that the model will be updated: "so if validation is
successful the component's model will be updated according to the submitted
value"
The key is that it does validation, etc, just like a form submit would do.
It just does it on a local (i.e. single component) level rather than for
the entire form. If you don't want the model updated,
override getUpdateModel() and return false.
--
Jeremy Thomerson
http://www.wickettraining.com
On Wed, Apr 28, 2010 at 5:24 PM, Joseph Pachod <josephpachod@thomas-daily.de
> wrote:
>
> hi
>
> I was quite surprised, recently, by the AjaxFormComponentUpdatingBehavior,
> which directly updates the model. At the time it seemed pretty odd but I
> moved on.
>
> then I recently read this article from Igor, Building a ListEditor form
> component (
> http://wicketinaction.com/2008/10/building-a-listeditor-form-component/comment-page-1/)
> which states "in order to be a good citizen in Wicket’s form processing" a
> component should "Implement atomic form updates – this is perhaps the most
> important feature. If the user moves an item up or down in the list this
> change should not be reflected in the model object until the form is
> submitted."
>
> However, the AjaxFormComponentUpdatingBehavior completely breaks this
> important aspect, by going directly at the model. Furthermore, the javadoc
> doesn't illustrate how dangerous it is. For example, setting
> setDefaultFormProcessing on some cancel button won't work anymore. Neither
> does the javadoc hint at some ways to avoid this.
>
> Among the way to avoid this, I currently mostly see the
> AjaxFormValidatingBehavior or writing an ad hoc form component copying his
> initial state and implementing IFormModelUpdateListener.
>
> Thinking back on my initial issue, a Behavior which would only update the
> input of the component would have been resolved it (issue was a listview
> where adding a line would loose non submitted input on textfields).
>
> A such "AjaxFormComponentConvertingBehavior" is in fact easy to do, it's a
> copy of AjaxFormComponentUpdatingBehavior with a shortened onEvent:
> @Override
> protected final void onEvent(final AjaxRequestTarget target) {
> final FormComponent<?> formComponent = getFormComponent();
>
> if (getEvent().toLowerCase().equals("onblur") &&
> disableFocusOnBlur()) {
> target.focusComponent(null);
> }
>
> try {
> formComponent.inputChanged();
> onUpdate(target);
> } catch (RuntimeException e) {
> onError(target, e);
>
> }
> }
>
> Such a behavior would resolve some of the use case currently "wrongly"
> addressed by the AjaxFormComponentUpdatingBehavior. It could even be its
> parent class and be spoken of in its javadoc.
>
> What your feelings on that ?
>
> sorry for this long post and thanks in advance for your answers (which most
> likely will show I've missed something obvious there!).
>
> ++
> joseph
>