问题
Lets say I have form build in GWT, an UI-Binder, which implements Editor interface (com.google.gwt.editor.client.Editor) with two date fields (date from and to). Bean class is expected to have members:
Date fromDate; // with getter and setter Date toDate; // with getter and setter
And okay, while having bean class defined as written, there is no problem, but just after I add something like this:
public boolean hasFromDate()
{
return fromDate != null;
}
I got compilation error (for example for fromDate):
[ERROR] Line 17: The method hasFromDate() is undefined for the type Date
[ERROR] Line 20: The method setFromDate(Date) is undefined for the type Date
The generated code in temporary file (qualifiedBeanClass_fromDate_Context.java) appears to have:
@Override public java.util.Date getFromModel() {
return (parent != null && true) ? parent.getToDate().hasToDate() : null;
}
@Override public void setInModel(java.util.Date data) {
parent.getToDate().setToDate(data);
}
Where parent is my bean class. This is terribly wrong, cause getToDate() returns Date (or null) instance, so there is absolutely nothing wrong about the compilation error. Problem is, why GWT cares about those methods (hasToDate/hasFromDate) or is it a mandatory to have only getter/setter methods?
来源:https://stackoverflow.com/questions/28719713/gwt-editor-with-not-only-getter-setter-bean-class