The Artima Developer Community
Sponsored Link

Java Community News
A Closer Look at Beans Binding

5 replies on 1 page. Most recent reply: Feb 13, 2008 10:58 AM by James Watson

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 5 replies on 1 page
Frank Sommers

Posts: 2642
Nickname: fsommers
Registered: Jan, 2002

A Closer Look at Beans Binding Posted: Feb 12, 2008 3:29 PM
Reply to this message Reply
Summary
Beans Binding (JSR 295) is a new JCP standard for binding two bean properties, especially in UI components. In a recent pair of tutorials, Geertjan Wielenga explains with two short examples how to create a master-detail UI with Beans Binding and Swing.
Advertisement

Most tutorials on Beans Binding (JSR 295) have, up to now, focused either on the minute details of this new API, or demonstrated how NetBeans could automate much of tedium of binding user interface properties to business objects and vice versa. As a result, much example code available for Beans Binding is either specific to NetBeans and its GUI editor, or confined to small snippets illustrating some detail of the JSR 295 API.

NetBeans evangelist Geertjan Wielenga has recently broke that mold, and created two short, to-the-point examples that don't rely on automatic code generation in NetBeans, but that also provide a complete overview of a master-view UI with Swing and Beans Binding, in Beans Binding Via The Road Less Travelled By:

At the end of this blog entry, you'll have a JFrame that contains a JTable. The JTable is filled with data from a database. Whenever you select a row in the JTable, the JTextFields below the JTable are filled with the data from the currently selected row...

In the explanation that follows, we will ONLY use the code editor. Nothing will be generated. And, again, I could have used a Swing Application Framework template to generate all of the above (plus a lot more, such as CRUD functionality)...

In the second example, Wielenga shows how to create a similar UI using a JList.

The examples use client-side JPA data access, requiring an entity object. Once the data access part of the application is set up, Wielenga focuses on binding properties of the JTable to properties of the business entity, and then creating text field components that are, in turn, bound to the selected element in the table:

Note the pattern by which things happen: we create a binding group, we add other binding groups to it, within which we add bindings. The bindings use expression language to link to database column names, they also specify table column names and the type of the data...

What do you think of the Beans Binding API?


andries spies

Posts: 3
Nickname: wildfirexy
Registered: Nov, 2007

Re: A Closer Look at Beans Binding Posted: Feb 12, 2008 9:55 PM
Reply to this message Reply
Would love to have an opinion about it. What is the URL to the BLOG?

Frank Sommers

Posts: 2642
Nickname: fsommers
Registered: Jan, 2002

Re: A Closer Look at Beans Binding Posted: Feb 13, 2008 8:03 AM
Reply to this message Reply
Ah, thanks for pointing that out. Just added a URL.

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: A Closer Look at Beans Binding Posted: Feb 13, 2008 9:14 AM
Reply to this message Reply
I know it's just an example but the bean is pretty extraneous. I mean, why should I have to code up a Customer class just so I use it like a map or dict?

It just seems like a lot of complexity all in order to hardcode the structure of the database table in Java.

Frank Sommers

Posts: 2642
Nickname: fsommers
Registered: Jan, 2002

Re: A Closer Look at Beans Binding Posted: Feb 13, 2008 10:18 AM
Reply to this message Reply
> I know it's just an example but the bean is pretty
> extraneous. I mean, why should I have to code up a
> Customer class just so I use it like a map or dict?
>
> It just seems like a lot of complexity all in order to
> hardcode the structure of the database table in Java.

Well, the bean in the example is more like a messenger object used to ferry data between the database and the UI. As the article notes, these sorts of objects can be generated automatically from a database schema by NetBeans.

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: A Closer Look at Beans Binding Posted: Feb 13, 2008 10:58 AM
Reply to this message Reply
> > I know it's just an example but the bean is pretty
> > extraneous. I mean, why should I have to code up a
> > Customer class just so I use it like a map or dict?
> >
> > It just seems like a lot of complexity all in order to
> > hardcode the structure of the database table in Java.
>
> Well, the bean in the example is more like a messenger
> object used to ferry data between the database and the UI.

Precisely my point. The bean class is extraneous.

> As the article notes, these sorts of objects can be
> generated automatically from a database schema by NetBeans.

Being able to generate pointless code doesn't make it less pointless. And it doesn't change the fact that the classes need to be created.

It's one thing to create domain objects with behaviors and bind them to a database and UI but they way most beans are used is as a glorified working storage area.

Flat View: This topic has 5 replies on 1 page
Topic: Daniel Spiewak on Idiomatic Scala Features Previous Topic   Next Topic Topic: IntelliJ Does Flex

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use