Hey, im trying to build a simple Listview showing ...
# tornadofx
a
Hey, im trying to build a simple Listview showing some houses with their name and the number of rooms. Somehow i'm unable to get the size of roomsList to display it. I think i'm not doing this property thing right at all ... Maybe someone could give me a hint at this
Copy code
class House(name: String = "", rooms: List<Room> = emptyList()) : NamedObject(name)
{
	val roomsProperty = SimpleListProperty<Room>(this, "rooms ",rooms.asObservable())
	var rooms : ObservableList<Room> by roomsProperty
}

class HouseModel(house: ObjectProperty<House>) : ItemViewModel<House>(itemProperty = house)
{
	val name = bind(House::nameProperty)
	val rooms = bind(House::roomsProperty)
}
...

class HouseListFragment : ListCellFragment<House>() {
    private val controller by inject<QuotationController>()
    private val house = HouseModel(itemProperty)

    override val root = vbox {
        hbox {
            vbox {
                removeWhen { editingProperty }
                label(house.name) {
                    setId(Styles.contentLabel)
                    hgrow = Priority.ALWAYS
                    useMaxSize = true
                }
                label(house.rooms.value.size.toString())
                label(" rooms ") {}
            }
        }
    }
}
Doing something like
private val roomNumber = SimpleIntegerProperty(house.rooms.value.size)
always gives me 0 for a house which should have 3 rooms
private val roomNumber = integerBinding(house.rooms.value) {count() }
also returns displays as 0
Got it working with this code. But i dont really get why, or what was wrong before..,
Copy code
class HouseModel : ItemViewModel<House>()
{
	val name = bind(House::nameProperty)
	val rooms = bind(House::roomsProperty)
}

class HouseListFragment : ListCellFragment<House>()
{
	private val controller by inject<QuotationController>()
	private val house = HouseModel().bindTo(this)

	override val root = vbox {
		hbox {
			vbox {
				removeWhen { editingProperty }
				label(house.name) {
					setId(Styles.contentLabel)
					hgrow = Priority.ALWAYS
					useMaxSize = true
				}
				label(stringBinding(house.rooms) { "${value?.size} rooms in this house" })
			}
Should one just not put nested objects / lists of other objects in a ItemViewModel?