我在同一个FXML视图上有两个TableViews,Date和Orders,我已经将数据填充到Date TableView,但是当用户选择Date TableView行时,我想在订单Tableview上填充数据。
方案是当用户选择行时,Orders表会填充并显示在该日期发生的订单明细。
我知道我必须实施listner,我试过here
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
clientOrderDetail_tableCol_no.setCellValueFactory(new PropertyValueFactory<OrderDetail, Integer>("id"));
clientOrderDetail_tableCol_items.setCellValueFactory(new PropertyValueFactory<OrderDetail, String>("items"));
clientOrderDetail_tableCol_quantity.setCellValueFactory(new PropertyValueFactory<OrderDetail, Integer>("quantity"));
clientOrderDetail_tableCol_totalPrice.setCellValueFactory(new PropertyValueFactory<OrderDetail, Double>("total"));
clientOrderDetail_tableCol_pay.setCellValueFactory(new PropertyValueFactory<OrderDetail, Double>("pay"));
clientOrderDetail_tableCol_due.setCellValueFactory(new PropertyValueFactory<OrderDetail, Double>("due"));
clientOrderDetail_tableCol_paymentType.setCellValueFactory(new PropertyValueFactory<OrderDetail, String>("payType"));
clientOrderDetail_tableCol_dates.setCellValueFactory(new PropertyValueFactory<OrderDetail, String>("dates"));
//HERE I TRIED LISTNER
clientOrderDetail_tableView_dates.getSelectionModel().selectedItemProperty().addListener((obs, oldSelection, newSelection) -> {
refreshTable(newSelection.getDate());
});
}
我的tableRefresh方法是
public void refreshTable(String date)
{
//String date = clientOrderDetail_tableView_dates.getSelectionModel().getSelectedItem().getDate();
Connection c = null;
Statement stmt = null;
try{
c = DataBase.getConnection();
stmt = c.createStatement();
System.out.println(date);
ResultSet rs = c.createStatement().executeQuery
("SELECT * FROM ORDERS WHERE "
+ "DATE = "+date+"");
while (rs.next())
{
OrderDetail order = new OrderDetail();
order.id.set(Integer.parseInt( rs.getString("ID")));
order.payType.set(rs.getString("PAYTYPE"));
order.pay.set(Double.parseDouble(rs.getString("PAY")));
order.due.set(Double.parseDouble(rs.getString("DUE")));
order.total.set(Double.parseDouble(rs.getString("TOTAL")));
data.add(order);
}
clientOrderDetail_tableView.setItems(data);
stmt.close();
c.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
我的OderDetail课程
package structure;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
public class OrderDetail {
public SimpleIntegerProperty id = new SimpleIntegerProperty();
public SimpleStringProperty items = new SimpleStringProperty();
public SimpleIntegerProperty quantity = new SimpleIntegerProperty();
public SimpleDoubleProperty total = new SimpleDoubleProperty();
public SimpleDoubleProperty pay = new SimpleDoubleProperty();
public SimpleDoubleProperty due = new SimpleDoubleProperty();
public SimpleStringProperty payType = new SimpleStringProperty();
public SimpleStringProperty date = new SimpleStringProperty();
public void setID(Integer idSet)
{
id.set(idSet);
}
public Integer getId() {
return id.get();
}
public void setName(String itemNameSet) {
items.set(itemNameSet);
}
public String getName() {
return items.get();
}
public void setQuantity(Integer quantitySet)
{
quantity.set(quantitySet);
}
public Integer getQuantity() {
return quantity.get();
}
public void setTotal(Double totalPriceSet) {
total.set(totalPriceSet);
}
public Double getTotal() {
return total.get();
}
public void setPay(Double paySet) {
pay.set(paySet);
}
public Double getPay() {
return pay.get();
}
public void setDue(Double dueSet) {
due.set(dueSet);
}
public Double getDue() {
return due.get();
}
public void setPayType(String paymentTypeSet) {
payType.set(paymentTypeSet);
}
public String getPayType() {
return payType.get();
}
public void setDate(String dateSet) {
date.set(dateSet);
}
public String getDate() {
return date.get();
}
@Override
public String toString() {
return "OrderDetail [id=" + id + ", items=" + items + ", quantity=" + quantity + ", total=" + total + ", pay="
+ pay + ", due=" + due + ", payType=" + payType + ", dates=" + date + "]";
}
}
问题:当我从日期TableView中选择行时,给定的代码没有给出错误但是没有在Orders TableView中填充数据。
任何帮助都将受到高度赞赏。