Thanks .
It works (but seems a little duplication)

Andrew Geery <[email protected]> 於 2018年6月16日 週六 下午5:32寫道:

> You have to use the TextField constructor that specifies the type of the
> model:
>
> https://ci.apache.org/projects/wicket/apidocs/8.x/org/apache/wicket/markup/html/form/TextField.html#TextField-java.lang.String-org.apache.wicket.model.IModel-java.lang.Class-
>
> It should be:
>
>  add(new TextField<>("year", LambdaModel.of(obj::getYear, obj::setYear),
> Integer.class));
>
> That one always gets me too...
>
> Thanks
> Andrew
>
> On Sat, Jun 16, 2018 at 3:30 AM smallufo <[email protected]> wrote:
>
> > After upgrading to 8.0 , I tried the exciting LambdaModel , try to
> replace
> > the non-TypeSafety PropertyModel
> > But I found it cannot handle type intelligently.
> > For a TextField<Integer> , for example :
> >
> > form.add(new TextField<Integer>("year", LambdaModel.of(obj::getYear,
> > obj::setYear )));
> >
> > At runtime , it reports Cannot cast from String to Integer.
> >
> > I have to rewrite getter / setter to String type (and do conversion  in
> > setter ) , but the backing field is Integer type. (And change
> > TextField<Integer> to TextField<String> , or <> )
> >
> > This is pity ...
> > Did I miss anything ?
> >
> > Thanks.
> >
>

Reply via email to