Re: [8.0] TextField with LambdaModel forced to use String

2018-06-16 Thread Sven Meier
Hi,

regretfully Java lambdas don't provide type information via reflection.

Have fun
Sven

Am 16. Juni 2018 12:31:40 MESZ schrieb smallufo :
>Thanks .
>It works (but seems a little duplication)
>
>Andrew Geery  於 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  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 , for example :
>> >
>> > form.add(new TextField("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 to TextField , or <> )
>> >
>> > This is pity ...
>> > Did I miss anything ?
>> >
>> > Thanks.
>> >
>>


Re: [8.0] TextField with LambdaModel forced to use String

2018-06-16 Thread smallufo
Thanks .
It works (but seems a little duplication)

Andrew Geery  於 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  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 , for example :
> >
> > form.add(new TextField("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 to TextField , or <> )
> >
> > This is pity ...
> > Did I miss anything ?
> >
> > Thanks.
> >
>


Re: [8.0] TextField with LambdaModel forced to use String

2018-06-16 Thread Andrew Geery
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  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 , for example :
>
> form.add(new TextField("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 to TextField , or <> )
>
> This is pity ...
> Did I miss anything ?
>
> Thanks.
>


[8.0] TextField with LambdaModel forced to use String

2018-06-16 Thread smallufo
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 , for example :

form.add(new TextField("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 to TextField , or <> )

This is pity ...
Did I miss anything ?

Thanks.