permalmberg
01/28/2017, 11:00 AMDouble
. I have a base class like this:
abstract class BaseProperty<T> internal constructor(val header: String, protected val key: String, protected val defaultValue: T, protected val comp: Component) : ViewModel() {
var value: T by property(defaultValue)
fun valueProperty() = getProperty(BaseProperty<T>::value)
abstract fun updateValue(v: T)
abstract fun readValue() : T
fun init()
{
value = readValue()
}
init {
valueProperty().onChange {
updateValue(value)
}
}
}
from which I inherit a more specified "property handler": class IntProperty(header: String, key: String, defaultValue: Int, c: Component) : BaseProperty<Int>(header, key, defaultValue, c) {
override fun readValue(): Int {
return comp.getProperty(key, defaultValue)
}
override fun updateValue(v: Int) {
comp.setProperty(key, v)
}
}
In my ViewBuilder
(part of the ViewModel-layer) I do this:
override fun show(property: IntProperty) {
property.init()
with(myForm) {
field(property.header) {
textfield {
bind(property.valueProperty())
}
}
}
}
i.e. I bind to a BaseProperty<Int>::value
. This is working fine as long as only numbers are entered. As soon as a .
or other non-numbers are entered an exception is thrown. That is in itself is expected and I need to use a converter for that (I also want to add a validator). This is where I run into problems. The examples in the TFX guide all says to use the format textfield(model.name) { }
but I can't get that compile since it can't find an overload that matches - it seems want a Number
. Do I have any other option than to use Number
instead of Int
and Double
? My backend is in Java so it has no notion of Number
.