vmerk
11/03/2019, 1:31 PMItemViewModel
of a "Java-primitive" type.
The only way I figured out how to do this is to wrap it in a ObjectProperty
, but the bind {}
function seems to wrap the value in another property: Property<ObjectProperty<Boolean?>>
The values on the labels are:
nullableStringProperty1 = null
nullableStringProperty2 = null
nullableBooleanProperty1 = null
nullableBooleanProperty2 = false
Is there a cleaner way of dealing with nullable primitive types than Property<ObjectProperty<Boolean?>>
?
Thanks.Bogdan
11/03/2019, 1:55 PMproperty.value = null
vmerk
11/03/2019, 2:13 PMSimpleBooleanProperty
is a java class with an underlying primitive value, that cannot be null. And I don't know how to create a binding of type Property<Boolean>
that can contain null instead of Property<ObjectProperty<Boolean?>>
. I can use a SimpleStringProperty for a nullable String, because the underlying type is nullable though.iari
11/03/2019, 2:17 PMiari
11/03/2019, 2:24 PMT:Any
on it - it doesn't allow nullables.vmerk
11/03/2019, 2:24 PMbind
SimpleObjectProperty<Boolean?>
, you also get Property<SimpleObjectProperty<Boolean?>>
iari
11/03/2019, 2:25 PMBogdan
11/03/2019, 2:25 PMval b = objectProperty<Boolean?>(false)
vmerk
11/03/2019, 2:26 PMvmerk
11/03/2019, 2:26 PMiari
11/03/2019, 2:27 PMvmerk
11/03/2019, 2:27 PMvmerk
11/03/2019, 2:27 PMBoolean?
. what about Int?
?Bogdan
11/03/2019, 2:28 PMfalse
, true
, null
Bogdan
11/03/2019, 2:29 PMItem
), and not in the class ItemModel: ItemViewModel
Bogdan
11/03/2019, 2:32 PMvmerk
11/03/2019, 2:32 PMvar nullableBoolean: Boolean? by property(nullableBoolean)
with var nullableBoolean: Boolean? by objectProperty(nullableBoolean)
and i get an exception: Caused by: java.lang.ClassCastException: javafx.beans.property.SimpleObjectProperty cannot be cast to tornadofx.PropertyDelegate
could you please provide more context? a sample?Bogdan
11/03/2019, 2:35 PMclass Item(nullableBoolean: Boolean? = null) {
val nullableBooleanProperty = SimpleObjectProperty(this, "nullableBoolean", nullableBoolean)
}
class ItemModel : ItemViewModel<Item>() {
val nullableBooleanProperty = bind(Item::nullableBooleanProperty)
}
Bogdan
11/03/2019, 2:36 PMclass Item() {
val nullableBooleanProperty = SimpleObjectProperty<Boolean?>(this, "nullableBoolean")
}
vmerk
11/03/2019, 2:36 PMnullableBooleanProperty
is Property<SimpleObjectProperty<Boolean?>>
Bogdan
11/03/2019, 2:37 PMBogdan
11/03/2019, 2:37 PMvmerk
11/03/2019, 2:38 PMBogdan
11/03/2019, 2:38 PMiari
11/03/2019, 2:39 PMT
hast a xonstraint: T:Any
, that means, kotlin will never allow for a binding to retorn a Property<Result> where Result is a nullable Type.vmerk
11/03/2019, 2:39 PMProperty<Boolean>
instead somehow using bind
, that supports null? it works non-primitive typesBogdan
11/03/2019, 2:40 PMiari
11/03/2019, 2:41 PMProperty<Result>
where Result
is a nullable Type with bind.Bogdan
11/03/2019, 2:42 PMvmerk
11/03/2019, 2:42 PMProperty<ObjectProperty<Boolean?>>
vmerk
11/03/2019, 2:43 PMItemViewModel
Bogdan
11/03/2019, 2:43 PMBogdan
11/03/2019, 2:43 PMBogdan
11/03/2019, 2:46 PMvmerk
11/03/2019, 2:46 PMItemViewModel
. and you are suggesting that i just don't use it?iari
11/03/2019, 2:47 PMiari
11/03/2019, 2:48 PMiari
11/03/2019, 2:50 PMvmerk
11/03/2019, 2:51 PMiari
11/03/2019, 2:51 PMiari
11/03/2019, 2:52 PMiari
11/03/2019, 2:54 PMBogdan
11/03/2019, 2:55 PMvmerk
11/03/2019, 2:56 PMBogdan
11/03/2019, 2:58 PMvmerk
11/03/2019, 2:58 PMBogdan
11/03/2019, 3:01 PMSimpleBooleanProperty
- you need not to waste memory, not to create top objects. The rest you need to use ObjectProperty
iari
11/03/2019, 3:05 PMT:Any
with T:Any?
- and I only got one conflict with a list of changelisteners which also are constrained to Any
- that seems like an easy fix - however of course we don't know if that might break the implementation....vmerk
11/03/2019, 3:09 PMvmerk
11/03/2019, 3:37 PMT : Any?
to bind
and passing forceObjectProperty = true
produces the result that i wanted. not sure if i broke anything, all tests are passing..vmerk
11/03/2019, 3:47 PMbind
at all. i think adding forceObjectProperty
might be enoughvmerk
11/03/2019, 3:56 PMclass Item {
var nullableBoolean: Boolean by property()
val nullableBooleanProperty: ObjectProperty<Boolean> = getProperty(Item::nullableBoolean)
}
class ItemModel : ItemViewModel<Item>() {
val nullableBooleanProperty: Property<Boolean> = bind(Item::nullableBooleanProperty, forceObjectProperty = true)
}
Bogdan
11/03/2019, 4:05 PMBoolean?
vmerk
11/03/2019, 4:14 PMBoolean?
because of bind
Bogdan
11/03/2019, 4:15 PMBogdan
11/03/2019, 4:17 PMvmerk
11/03/2019, 4:20 PMBogdan
11/03/2019, 4:21 PM