Package 

Class ConvertersKt

    • Method Summary

      Modifier and Type Method Description
      final <BEAN extends Any, ID extends Any, ENTITY extends KEntity<ID>> Binder.BindingBuilder<BEAN, ID> toId(Binder.BindingBuilder<BEAN, ENTITY> $self) Converts an entity to its ID and back.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • toId

         final <BEAN extends Any, ID extends Any, ENTITY extends KEntity<ID>> Binder.BindingBuilder<BEAN, ID> toId(Binder.BindingBuilder<BEAN, ENTITY> $self)

        Converts an entity to its ID and back. Useful for combo boxes which shows a list of entities as their options while being bound to a field containing ID of that entity:

        data class Category(override var id: Long? = null, var name: String = "") : Entity<Long>
        data class Review(override var id: Long? = null, var category: Long? = null) : Entity<Long>
        
        // editing the Review, we want the user to be able to choose the Review's category
        val binder = BeanValidationBinder(Review::class.java)
        val categoryBox = comboBox("Choose a category") {
            setItemCaptionGenerator { it.name }
            isTextInputAllowed = false
            dataProvider = Category.dataProvider
            bind(binder).toId().bind(Review::category)
        }