I would really like to understand why the model object of the following code is always null, when the same model is used by a TextField and its surrounding FormComponentPanel:
public class MyPanel extends FormComponentPanel<String> {
private TextField<String> _field;
public MyPanel(String id, IModel<String> model) {
super(id, model);
_field = new TextField<String>("field", model);
add(_field);
}
}
I know I can fix this by overriding the Panel’s convertInput, which is described in the Javadocs:
@Override
protected void convertInput() {
setConvertedInput(_field.getConvertedInput());
}
I really would like to understand why the TextField’s changes do not update the model the way I would expect: Setting the model object to the user’s input.
As “Wicket in Action” says:
In your example initially the convertInput method of the text field will be called. It will update the shared model with the correct value.
Then the convertInput method of form component panel will be called. But because form component panel doesn’t receive any input directly its getInputAsArray method will return null (if input is nullable as in your case). So the shared model will be again updated, this time with null value, and the resulting value of the model will be null in the end.