Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 246 Vote(s) - 3.42 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to force Wicket "onchange" AJAX events to be triggered if fields fail validation conditions

#1
The specific case I've got in mind is as follows: an AjaxFormComponentUpdatingBehavior("onchange") is added to a TextField<String> in a form. The behavior **verifies the text for certain conditions** (either the model object or the form component model, doesn't matter), based on which it **might display a message** (or hide it, if it has already been shown).

The problem is, there are also validators added to the TextField. One of the possible (and likely) scenarios consists of the user typing in, **first, a value that causes the message to be displayed** by the AJAX request. If, then, he/she types in a **value that doesn't pass validation**, the **message should disappear**, but it does not.

Apparently, either the **onUpdate() method for the AJAX behavior is not called at all**, or I am failing in my attempts to insert a **check for non-validated entries** (I have tried to test for both null values and empty strings, to no avail; I have no idea what exactly Wicket's validators do to models when data is invalid).

I am wondering if someone who actually understands validators (or AJAX, actually) has any ideas on where the problem could be.

I can post edit and post code if someone tells me this is not a general issue tying validators and AJAX, but most likely a programming mistake. I still believe the former and thus I'll refrain from posting code sections, in order to keep the discussion on an API/theoretical frame.

Thanks.
Reply

#2
When using an `AjaxFormComponentUpdatingBehavior`, if any of the `IValidator`s fail their validation, [`onError()`](

[To see links please register here]

) will be called instead of [`onUpdate()`](

[To see links please register here]

). Wicket will effectively prevent invalid user input from reaching the `IModel`s in your components, so the component's ModelObject will not be changed at all. The invalid input will probably remain available by means of [`getInput()`](

[To see links please register here]

[`getConvertedInput()`](

[To see links please register here]

) (not sure if it will in an AJAX scenario, it sure is in a traditional form submission).

However, take into account that `IFormValidator`s are not executed when using this mechanism. If you've got any, you might be interested in overriding [`getUpdateModel()`](

[To see links please register here]

) so that `AjaxFormComponentUpdatingBehavior` will not bring maybe-invalid user input into your `IModel`s, and set modelobjects manually when you're certain user input is valid.

Regarding your specific case, you could perform all the required logic in `onError()` (or rely on `Model`s that will grab data from somewhere else), and just add the components that need refreshing to the `AjaxRequestTarget`. This is probably what's missing in your scenario.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through