Thanks Bas,

For now I'll fix it with explicit class in the constructor

I'm not sure but maybe method-references in the LambdaModel could also
determine their type can the model could be modified to pass that on?

-Rob

On Wed, Oct 4, 2017 at 8:54 PM, Bas Gooren <[email protected]> wrote:

> Rob,
>
> This is because a property model provides certain metadata (when
> available);
> E.g. When the property model points to a field, it provides the type of
> field.
> Even when the model value is null this type information is still available.
>
> Since this metadata is not available when using lambdas wicket uses a
> default (String).
>
> The reason it also works with a regular Model is because you provide a
> value; thus, wicket can detect the type based on the value.
>
> When your lambda does not return a value, wicket cannot detect the type.
>
> // Bas
>
> Verstuurd vanaf mijn iPhone
>
> > Op 4 okt. 2017 om 16:58 heeft Rob Audenaerde <[email protected]>
> het volgende geschreven:
> >
> > 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);
> >
> > }
> > }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

Reply via email to