My DTO Object contain another two objects. I need to set the value of those also in to the table.
controller.java
package controller;
import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXDatePicker;
import com.jfoenix.controls.JFXTextField;
import dto.AppointmentDTO;
import dto.DoctorDTO;
import dto.PatientDTO;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
public class AddAppointmentController implements Initializable {
@FXML
private TableView<AppointmentDTO> tblView;
private ObservableList<AppointmentDTO> tblData;
/**
* Initializes the controller class.
*/
@Override
public void initialize(URL url, ResourceBundle rb) {
tblData = FXCollections.observableArrayList();
tblView.getColumns().get(0).setCellValueFactory(new PropertyValueFactory<>("appointmentID"));
tblView.getColumns().get(1).setCellValueFactory(new PropertyValueFactory<>("appointDate"));
tblView.getColumns().get(2).getColumns().get(0).setCellValueFactory(new PropertyValueFactory<>("patientName"));
tblView.getColumns().get(2).getColumns().get(1).setCellValueFactory(new PropertyValueFactory<>("patienAge"));
tblView.getColumns().get(2).getColumns().get(2).setCellValueFactory(new PropertyValueFactory<>("ContactNumber"));
tblView.getColumns().get(3).getColumns().get(0).setCellValueFactory(new PropertyValueFactory<>("doctorName"));
tblView.getColumns().get(3).getColumns().get(1).setCellValueFactory(new PropertyValueFactory<>("hospital"));
tblData.add(new AppointmentDTO(12, "201", new PatientDTO(2, "uh", 12, "hj"), new DoctorDTO(4, "ghj", "ghj")));
tblView.setItems(tblData);
}
}
AppointmentDTO.java And this is fully encapsulated class.
package dto;
public class AppointmentDTO {
private int appointmentID;
private String appointDate;
private PatientDTO patientDTO;
private DoctorDTO doctorDTO;
}
PatientDTO is fully encapsulated with these properties;
private int patienID;
private String patientName;
private int patienAge;
private String ContactNumber;
DoctorDTO is also fully encapsulated with these properties;
private int doctorID;
private String doctorName;
private String hospital;
fx:ids on the table columns and referenced them directly.