DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Java
  4. Kotlin Properties and the Vaadin 8 Beanbinder [Code Snippet]

Kotlin Properties and the Vaadin 8 Beanbinder [Code Snippet]

The Vaadin 8 beta is taking some lessons from Java 8's implementation of lambda expressions. But whereas Java doesn't recognize properties, Kotlin can help bind beans.

Thomas Kratz user avatar by
Thomas Kratz
·
Jan. 18, 17 · Code Snippet
Like (4)
Save
Tweet
Share
6.50K Views

Join the DZone community and get the full member experience.

Join For Free

Vaadin 8 (currently in beta) comes with a whole new DataBinding API that makes heavy use of Java 8 lambda features. 

Unfortunately, Java has no concept of a Property, so one of the new ways to bind a Bean Property is writing something like ( taken from the documentation):


binder.bind(nameField, Person::getName, Person::setName);


Since Kotlin has a concept for a property, you may want to write something like:

binder.forField(nameField)
        .bind(Person::name)


That's possible with an extension method for the Vaadin Binder that could probably look like this:

fun <BEAN, T> Binder.BindingBuilder<BEAN, T>.bind(prop: KMutableProperty<T>) {
    this.bind(
            ValueProvider { bean: BEAN -> prop.getter.call(bean) },
            Setter { bean: BEAN, v: T -> prop.setter.call(bean, v) })
}


Have fun with Kotlin and Vaadin!

Vaadin Property (programming) Kotlin (programming language) Snippet (programming)

Published at DZone with permission of Thomas Kratz, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Web Application Architecture: The Latest Guide
  • The Future of Cloud Engineering Evolves
  • How To Generate Code Coverage Report Using JaCoCo-Maven Plugin
  • Kotlin Is More Fun Than Java And This Is a Big Deal

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: