We are preparing for migration to Wicket 8 (when it comes out). So we are
already replacing our old PropertyModels with a backported LambdaModel (we
use the implementation from Wicket 8).
I noticed an odd behavior where the RangeValidator gets an empty String
from the input (in validatable.getValue()) if the input is not an integer
(for example, changing '2' to '2e' in the textfield).
This results in a class cast exception.
If I replace the Lambdamodel by a IModel<Integer> = new Model<Integer>(2)
it works fine.
After adding the type Integer.class to the NumberTextField it works fine
again.
Am I doing something wrong?
Thanks!
Here is the relevant code (see commented section):
------
public class HomePage extends WebPage {
private static final long serialVersionUID = 1L;
static class MyInt implements Serializable
{
Integer i=2;
public Integer getI() {
return i;
}
public void setI(Integer i) {
this.i = i;
}
}
public HomePage(final PageParameters parameters) {
super(parameters);
IModel<MyInt> myInt = new Model(new MyInt());
IModel<Integer> intModel = LambdaModel.of(myInt, MyInt::getI, MyInt::setI);
Form f = new Form("f") {
};
//Next commented line does not work if you change the input for '2' to '2e'
and click outside the input box.
//NumberTextField ntf = new NumberTextField<>("tf", intModel);
NumberTextField ntf = new NumberTextField<>("tf", intModel, Integer.class);
ntf.setOutputMarkupId(true);
ntf.setMinimum( 1 ).setStep( 1 );
ntf.add( new OnChangeAjaxBehavior()
{
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate( AjaxRequestTarget target )
{
System.out.println("changed!");
}
} );
f.add(ntf);
add(f);
}
}