bad TableView example in the tutorial
Tom Schindl
tom.schindl at bestsolution.at
Thu Jul 30 07:37:45 UTC 2015
On 23.07.15 13:35, Henning Brackmann wrote:
> https://docs.oracle.com/javase/8/javafx/user-interface-tutorial/table-view
> .htm
>
>
>
> Why are the SimpleStringProperties in the person class private?
>
>
>
> IMHO the Person class should be:
>
>
>
> Example 13-3 Creating the Person Class
>
> public static class Person {
> public final SimpleStringProperty firstName;
> public final SimpleStringProperty lastName;
> public final SimpleStringProperty email;
>
> private Person(String fName, String lName, String email) {
> this.firstName = new SimpleStringProperty(fName);
> this.lastName = new SimpleStringProperty(lName);
> this.email = new SimpleStringProperty(email);
> }
> }
>
public fields are never a good idea! If you want a JavaFX Bean then
those should be exposed with firstNameProperty(): StringProperty, ...
>
> Example 13-5 Setting Data Properties to Columns
>
> firstNameCol. setCellValueFactory(param -> param.getValue().firstName);
> lastNameCol.setCellValueFactory(param -> param.getValue().lastName);
> emailCol.setCellValueFactory(param -> param.getValue().email);
>
>
> I think the tuturial should promote typesafe bindings.
>
The advantage of the PropertyValueFactory is that it also works for
Pojos/JavaBeans.
The real question is what one wants to present and teach people with
those examples.
If you eg want to make them aware of PropertyValueFactory because in
most applications data will be coming from a backend who most like only
sends simple DTOs then example is perfectly fine.
Tom
--
Thomas Schindl, CTO
BestSolution.at EDV Systemhaus GmbH
Eduard-Bodem-Gasse 5-7, A-6020 Innsbruck
http://www.bestsolution.at/
Reg. Nr. FN 222302s am Firmenbuchgericht Innsbruck
More information about the openjfx-dev
mailing list