Robert Jaros
01/31/2020, 8:25 AMgetData()
. Without serialization requirement you would have to pass some kind of factory function. I don't know any other way to construct a generic type object.Robert Cronin
01/31/2020, 11:46 AMRobert Jaros
01/31/2020, 1:14 PMFormPanel
without serialization requirement (why?) I could add an option to pass such factory function directly to FormPanel
. It would work fine with not serializable model class, but you would have to write a function Map<String,Any?> -> K
by yourself for your forms.Robert Cronin
01/31/2020, 1:16 PMRobert Cronin
01/31/2020, 1:17 PMRobert Jaros
01/31/2020, 1:19 PMRobert Cronin
01/31/2020, 1:20 PMRobert Jaros
01/31/2020, 1:30 PMRobert Jaros
01/31/2020, 1:40 PMRobert Jaros
01/31/2020, 2:30 PMRobert Jaros
01/31/2020, 2:39 PMStringFormControl
(e.g. Text
) on the FormPanel
containerRobert Jaros
01/31/2020, 2:42 PMFormPanel
constructor or builder
- add @ContextualSerialzation
to your field
- override a toString
method of your field classRobert Jaros
01/31/2020, 2:47 PM// not serializable class
class ObjectId(val id: Int) {
override fun toString(): String {
return "$id"
}
}
// custom serializer
object ObjectIdSerializer : KSerializer<ObjectId> {
override val descriptor: SerialDescriptor = SerialClassDescImpl("com.example.ObjectId")
override fun deserialize(decoder: Decoder): ObjectId {
val str = decoder.decodeString()
return ObjectId(str.toInt())
}
override fun serialize(encoder: Encoder, obj: ObjectId) {
encoder.encodeString(obj.id.toString())
}
}
// Form model
@Serializable
data class Form(
val text: String? = null,
val password: String? = null,
val password2: String? = null,
val textarea: String? = null,
val richtext: String? = null,
val date: Date? = null,
val time: Date? = null,
val checkbox: Boolean = false,
val radio: Boolean = false,
val simpleSelect: String? = null,
val select: String? = null,
val ajaxselect: String? = null,
val spinner: Double? = null,
val radiogroup: String? = null,
val upload: List<KFile>? = null,
@ContextualSerialization val objectId: ObjectId? = null
)
// FormPanel initialization
val formPanel = formPanel<Form>(customSerializers = mapOf(ObjectId::class to ObjectIdSerializer)) {
// Add custom field and String control to the form
addCustom(Form::objectId, Text(label = "ObjectId"))
// get form data
formPanel.getData()
formPanel.getDataJson()
// set form data
formPanel.setData(Form(objectId = ObjectId(14)))
Robert Jaros
01/31/2020, 2:49 PMRobert Cronin
02/01/2020, 9:32 AMRobert Cronin
02/01/2020, 9:32 AMRobert Cronin
02/01/2020, 9:33 AM