如何将 LocalDate 与 Binding 结合使用
How to use LocalDate with Binding
我的应用程序包含用户输入姓名、电子邮件等的部分,但他们也可以添加日期(它没有初始值)
日期是一个 DatePicker。
我所做的是添加一个绑定到 "submit" 按钮,以确保用户在按钮可用之前输入了所有信息,但是,我不知道如何绑定到LocalDate.
我尝试了这个有效的方法(除了最后的 date.getValue()):
public BooleanBinding isEitherFieldEmpty() { //This is for the "SUBMIT binding" to check if all text fields are empty
return txtFirstName.textProperty().isEmpty().or(txtSurname.textProperty().isEmpty()).or
(txtPNumber.textProperty().isEmpty()).or(txtEmail.textProperty().isEmpty()).or(date.getValue() == null);
}
最后一部分:.or(date.getValue() == null);
给我一个错误
The method or(ObservableBooleanValue) in the type BooleanExpression is not applicable for the arguments (boolean)
我想知道是否还有另一种方法可以将按钮也绑定到 LocalDate。
谢谢
假设 date
是 DatePicker
,您可以只使用
date.valueProperty().isNull()
其中 returns 个 BooleanBinding
。即:
public BooleanBinding isEitherFieldEmpty() { //This is for the "SUBMIT binding" to check if all text fields are empty
return txtFirstName.textProperty().isEmpty()
.or(txtSurname.textProperty().isEmpty())
.or(txtPNumber.textProperty().isEmpty())
.or(txtEmail.textProperty().isEmpty())
.or(date.valueProperty().isNull());
}
我的应用程序包含用户输入姓名、电子邮件等的部分,但他们也可以添加日期(它没有初始值)
日期是一个 DatePicker。
我所做的是添加一个绑定到 "submit" 按钮,以确保用户在按钮可用之前输入了所有信息,但是,我不知道如何绑定到LocalDate.
我尝试了这个有效的方法(除了最后的 date.getValue()):
public BooleanBinding isEitherFieldEmpty() { //This is for the "SUBMIT binding" to check if all text fields are empty
return txtFirstName.textProperty().isEmpty().or(txtSurname.textProperty().isEmpty()).or
(txtPNumber.textProperty().isEmpty()).or(txtEmail.textProperty().isEmpty()).or(date.getValue() == null);
}
最后一部分:.or(date.getValue() == null);
给我一个错误
The method or(ObservableBooleanValue) in the type BooleanExpression is not applicable for the arguments (boolean)
我想知道是否还有另一种方法可以将按钮也绑定到 LocalDate。
谢谢
假设 date
是 DatePicker
,您可以只使用
date.valueProperty().isNull()
其中 returns 个 BooleanBinding
。即:
public BooleanBinding isEitherFieldEmpty() { //This is for the "SUBMIT binding" to check if all text fields are empty
return txtFirstName.textProperty().isEmpty()
.or(txtSurname.textProperty().isEmpty())
.or(txtPNumber.textProperty().isEmpty())
.or(txtEmail.textProperty().isEmpty())
.or(date.valueProperty().isNull());
}