in my form I have textField:
add(new TextField<String>("awayScore", new PropertyModel<String>(value, "awayScore") {
private static final long serialVersionUID = 1L;
@Override
public String getObject() {
logger.info("textField");
return super.getObject();
}
}));
as you can see I just add logger.
I didnt see anything wrong here but when I run my application I got this error:
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
at org.toursys.web.PlayOffPage$PlayOffForm$2$1$1.getObject(PlayOffPage.java:135)
row 135 contains:
return super.getObject();
I am really confused about it because without overriding this works
UPDATE:
when I edit my code to:
Object value = super.getObject();
logger.error(value.getClass() + "");
this code return:
class java.lang.Integer
which is really weird because according to compiler this should return String
When you write
new PropertyModel<String>(value, "awayScore")you make a promise that theawayScorein yourvalueis aString. The compiler can’t verify your claim and there’s no automatic conversion.In
AbstractPropertyModelthe methodgetObjectis defined to return aTwhich will get replaced byObject. That’s the reason it still works. As soon as you override the method to returnStringthe cast will fail.