You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by marco di gasbarro <m....@gmail.com> on 2016/05/11 15:31:17 UTC

when a Form validation fails, components don't refresh correctly

Hey All,
I'm dealing with a user interaction problem after a failed Form validation.
In fact I have a Form with two components: a DropDownChoice and a TextField.
The DropDownChoice has an AjaxFormComponentUpdatingBehavior attached, which
modifies the TextField's model object and then adds the TextField itself to
the AjaxRequestTarget.

When the Form validation fails, the DropDown's Behavior changes the
TextField's underlying model object correctly, adds the TextField to the
Target, but the TextField renders with the old converted input, which
doesn't reflect the changes.

If on the one hand it looks like a Wicket's feature to leave the Form
components showing the input which couldn't be validated, on the other hand
a flexible user interaction should let the component to be notified about
the changes occurred on its model object.

By now I work around it calling inputChanged() on the TextField before
adding it to the Target.
Is there any best practice which covers this use case?

Here is a snippet:

new AjaxFormComponentUpdatingBehavior("change"){
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                    //update the TextField model object

getMyFormModelObject().setMyTextFieldModelObject(newValue);
                    //temporary workaround
                    myTextField.inputChanged();
                    //add the textfield to the Target
                    target.add(myTextField);
     }
}


Thanks in advance for your help!
--
Marco

Re: when a Form validation fails, components don't refresh correctly

Posted by Sven Meier <sv...@meiers.net>.
Hi,

calling myTextField.clearInput() would be the recommended solution.

Have fun
Sven


On 11.05.2016 17:31, marco di gasbarro wrote:
> Hey All,
> I'm dealing with a user interaction problem after a failed Form validation.
> In fact I have a Form with two components: a DropDownChoice and a TextField.
> The DropDownChoice has an AjaxFormComponentUpdatingBehavior attached, which
> modifies the TextField's model object and then adds the TextField itself to
> the AjaxRequestTarget.
>
> When the Form validation fails, the DropDown's Behavior changes the
> TextField's underlying model object correctly, adds the TextField to the
> Target, but the TextField renders with the old converted input, which
> doesn't reflect the changes.
>
> If on the one hand it looks like a Wicket's feature to leave the Form
> components showing the input which couldn't be validated, on the other hand
> a flexible user interaction should let the component to be notified about
> the changes occurred on its model object.
>
> By now I work around it calling inputChanged() on the TextField before
> adding it to the Target.
> Is there any best practice which covers this use case?
>
> Here is a snippet:
>
> new AjaxFormComponentUpdatingBehavior("change"){
>                  @Override
>                  protected void onUpdate(AjaxRequestTarget target) {
>                      //update the TextField model object
>
> getMyFormModelObject().setMyTextFieldModelObject(newValue);
>                      //temporary workaround
>                      myTextField.inputChanged();
>                      //add the textfield to the Target
>                      target.add(myTextField);
>       }
> }
>
>
> Thanks in advance for your help!
> --
> Marco
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org