Binding BeanModelProvider to a chained Bean Interface

21 views
Skip to first unread message

FrankGWT

unread,
Sep 9, 2010, 4:58:09 PM9/9/10
to GWT Pectin
We are using interface instead of concrete class whenever possible in
our code. I am having problem when binding a BeanModelProvider to a
chained Bean Interface.

For example bean "Employee" implements Interface IEmployee which
implements interface IPeople. When binding BeanModelProvider to
interface "IEmployee" instead of the bean class "Employee", it seems
the getters and setters in the IPeople interface were not picked up by
Pectin. Hit by a "UnknownPropertyException" when a
"getPropertyType"method of BeanModelProvider was called.

Thanks a lot for your help!

Here is the code example:

public Interface IPeople {

public String getGivenName();
public void setGivenName(String givenName);

}

public Interface IEmployee extends IPeople {
public String getJobTitle();
public String setJobTitle();
}

public class Employee implements IEmployee {
private String givenName;
private String jobTitle;
// implements getters and setters of givenName and jobTitle
fields
...
}

public class BasicFormModel extends FormModel
{
public static abstract class EmployeeProvider extends
BeanModelProvider<IEmployee> {}
public static EmployeeProvider employeeProvider =
GWT.create(EmployeeProvider.class);

protected final FieldModel<String> givenName;

public BasicFormModel() {

// the following line will return a "UnknownPropertyException
Unknown property: givenName"
givenName =
fieldOfType(String.class).boundTo(employeeProvider, "givenName");
}
}

Andrew Pietsch

unread,
Sep 9, 2010, 7:30:08 PM9/9/10
to gwt-pecti...@googlegroups.com
Yep, the rebind code isn't checking interfaces.  Can you raise an issue for it?

If you feel like writing a patch the methods are:

BeanInfo.getMethods // rebind package
BeanDescriptor.findMethod // reflect package

To update the tests:
Create a new interface with some properties and have TestBean implement it (in testCommon).  (Should also move some properties to a super class, I thought I had that... but I must have dropped it when I created the testCommon code.. doh.).
Update BeanModelProviderPropertyDescriptorTestRunner.c_isMutable, .j_getValueType (and possibly .k_getElementType) to use the new properties.  This test could do with some clean up & polish but no matter (c:

Note: The ugly testing code is because I want to share common test code between the reflection and GWT providers.  There's nothing speciall about the letter prefixes, it just helps me make sure the actual tests (in test and gwtTest) are calling all the method in the runners.  If you want to add a new test just add it at the bottom with the next letter.

Cheers

FrankGWT

unread,
Sep 10, 2010, 4:24:59 PM9/10/10
to GWT Pectin
Thanks, Andrew. Those tips are really helpful. I will try to make a
patch and let you know.
Frank

Andrew Pietsch

unread,
Sep 11, 2010, 6:00:42 AM9/11/10
to gwt-pecti...@googlegroups.com
No worries, thanks for having a look at it.

Cheers
Reply all
Reply to author
Forward
0 new messages