Menu

Create a View Object

Ralph

A View Object is needed to display and manipulate values in a form or in a list of records.

A view object is something like a ValueObject or a TransferDataObject (DTO). But these classes are designed to improve access and transfer of data between parts of an application.

A view object is used to create a clear cut between data access in the database and data manipulation in the frontend.

You can use a view object without making the data persistent but it is possible to map data between entities and view objects. Attributes of a view object are used to display data in a form or a list. Attributes of entities are used to fill data in the database.

Example of a View Object:

package de.hoppe.extra.vo;

import de.hoppe.extra.model.Druckort;
import de.hoppe.fxDb.controller.ViewObjectProperty;
import de.hoppe.fxDb.vo.ViewObject;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleLongProperty;
import javafx.beans.property.SimpleStringProperty;

public class VoPerson extends ViewObject {

  private SimpleStringProperty search = new SimpleStringProperty();
  private SimpleStringProperty surname = new SimpleStringProperty();
  private SimpleStringProperty givenname = new SimpleStringProperty();
  private SimpleStringProperty phone = new SimpleStringProperty();
  private SimpleStringProperty email = new SimpleStringProperty();
  private SimpleStringProperty salutation = new SimpleStringProperty();
  private SimpleStringProperty dbUsername = new SimpleStringProperty();

  private SimpleLongProperty id;

  public Object getPrimaryKey() {
    return getId();
  }

  public String getSearch() {
    if (search == null) {
      return "";
    } else {
      return search.get();
    }
  }

  @ViewObjectProperty(name="search")
  public SimpleStringProperty searchProperty() {
    return search;
  }
}

You can see the view object starts with prefix Vo. This is only a convention but is useful.
The view object VoPerson is extending de.hoppe.fxDb.vo.ViewObject.
You can see the get- and the set- method as it is usual in Java beans.

But you can also find that this bean has a ...Property- method implemented.
This is used to provide data for JavaFX.


Next step is to [Create a JavaFX Stage].


Related

Wiki: Create a JavaFX Stage
Wiki: Create an Entity

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.