Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added fallback to have support for read-only properties #168

Merged
merged 4 commits into from Mar 29, 2016

Conversation

@uc-mobileapps
Copy link
Contributor

@uc-mobileapps uc-mobileapps commented Mar 25, 2016

Hello Matti,
my proposal to have support for default methods added to the entities.
E.g.

public interface WordLength {
  String getWord();
  default int getWordLength() {
    String w = getWord();
    return w != null ? w.length() : 0;
  }
}

One can then bind the readonly field as well. I don't know whether there are other components where this feature also makes sense.
Though this is actually a work around since commons beanutils doesn't support it.
hth

@mstahv
Copy link
Member

@mstahv mstahv commented Mar 25, 2016

Hi, do you have a full example/test case for the usage? I guess we cannot commit it yet to the project though, as we want to maintain Java 7 compatibility.

@uc-mobileapps
Copy link
Contributor Author

@uc-mobileapps uc-mobileapps commented Mar 26, 2016

Hi Matti,
have added a testcase AspectAttributeTest so you can see what the code can be used for.
I configured the maven pom to have the Java source level 8 for the test compile. The changes that were done to the viritin lib run in 1.7 without modifications since they only use regular reflection api calls introduced in 1.5
Regards Klaus

*/
private static Method obtainGetterOfProperty(DynaClass beanClass, String propertyName) throws ClassNotFoundException, NoSuchMethodException, SecurityException {
Class<?> clazz = Class.forName(beanClass.getName());
return clazz.getMethod("get"+firstLetterUppercase(propertyName));

This comment has been minimized.

@mstahv

mstahv Mar 29, 2016
Member

Maybe add support for booleans ("is" vs "get") as well ?

<execution>
<id>default-testCompile</id>
<configuration>
<source>1.8</source>

This comment has been minimized.

@mstahv

mstahv Mar 29, 2016
Member

This is awesome improvement, not only for this change! And at least NetBeans seems to understand these instructions perfectly.

@mstahv mstahv merged commit 573369d into viritin:master Mar 29, 2016
@mstahv
Copy link
Member

@mstahv mstahv commented Mar 29, 2016

Excellent stuff, I merge it to master now, but I'd at least look at the boolean value thingie.

BTW. Do you know if PropertyDescriptor supports Java 8 default methods? That's used by BeanItem in core Vaadin:
https://github.com/vaadin/vaadin/blob/master/server/src/com/vaadin/data/util/BeanUtil.java

If it does, then we should probably use that.

@uc-mobileapps
Copy link
Contributor Author

@uc-mobileapps uc-mobileapps commented Apr 2, 2016

It doesn't unfortunately, added a test method to try it out

@Test
public void testPropertyDescriptor() throws Exception {
    List<PropertyDescriptor> propertyDescriptor = BeanUtil.getBeanPropertyDescriptor(User.class);
    assertTrue("Default read-only property not found", 
            propertyDescriptor.stream().anyMatch(pd -> "localizedSalutation".equals(pd.getName())));
}

Glad you liked my ideas, yet I find even better that I can now use them with standard viritin, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.