I have a javascript function that is being called from an actionscript component with a byte array of data. The function is correctly being called and I can validate the data being received.
I need to get that data back into wicket, but if I set the value of a component using javascript and fire the onChange event, I see the event but the model of the component has not been updated, e.g.:
Javascript Function
<script type="text/javascript">
function f(obj) {
document.getElementById("byteArray").value = obj.byteArray;
document.getElementById("byteArray").onchange();
}
</script>
Wicket Behaviour
final TextField field = new TextField("byteArray", Model.of(""));
field.add(new AjaxEventBehavior("onChange") {
@Override
protected void onEvent(AjaxRequestTarget target) {
String byteArray = getComponent().getDefaultModelObjectAsString());
// byteArray has not changed here
}
});
I have tried using a PropertyModel and an IModel implementation with no joy. I have been able to get the data back into Wicket using a form submission, but that forces a page refresh which is no good for my application. I have not been able to successfully fire a AjaxFormSubmission event of any type programmatically from Javascript.
I have been tried using wicketAjaxGet / Post to submit the data but I get a 413 error because my byte array is too large.
Any ideas?
Use AjaxFormComponentUpdatingBehavior instead of AjaxEventBehavior. It is meant for pushing the contents into the model after the converter and all validators have run… Keep in mind that if the input does not pass conversion or validation, it will not update the model, rather the onError method will be called (vs the onUpdate method).
Besides the switch to the new behavior, everything else should be able to remain the same.