My use case is quite complex, but I'll try my best to simplify it to make my problem as clear as possible. Bear with me, please.
On my server I have data models. These models may model any kind of objects, like chairs, people, animals or computer parts. I do not know in advance what these models will be, and my app needs to work for all kinds of models. You can think of the models as class definitions. My job is to build forms to populate these models with data, in order to create instances of these classes.
Each field in the model is of some data type (like string, or date), and can be present in the instance one or multiple times. Sometimes I know how many times the field may be present, sometimes there is no upper limit. For example, there is no upper bound to how many pets a person may own.
Right now I have one data source that is used to fetch a mold for the data sources used in the form. The data from the server (for i.e. a person) could look something like this (where quantity denotes the maximum number of entries per field, and * means there s no upper bound):
The data source backing the form will then get the response and build an appropriate form based on this, like so:
This is all working fine, but my problem is that with fields where the user could want to supply more than one, or some unknown amount, I don't know how to add these fields to the data source. I've tried adding them after the data source has been created, but this is not allowed. I can't keep them hidden, as I don't have an upper bound, and since the format is not fixed I can't use an editable listgrid.
How can I achieve this? Thankful for any suggestions.
On my server I have data models. These models may model any kind of objects, like chairs, people, animals or computer parts. I do not know in advance what these models will be, and my app needs to work for all kinds of models. You can think of the models as class definitions. My job is to build forms to populate these models with data, in order to create instances of these classes.
Each field in the model is of some data type (like string, or date), and can be present in the instance one or multiple times. Sometimes I know how many times the field may be present, sometimes there is no upper limit. For example, there is no upper bound to how many pets a person may own.
Right now I have one data source that is used to fetch a mold for the data sources used in the form. The data from the server (for i.e. a person) could look something like this (where quantity denotes the maximum number of entries per field, and * means there s no upper bound):
Code:
"name": {"id":"name", "type":"text", "name":"Name", "quantity":"3" }, "age": {"id":"age", "type":"integer", "name":"Age", "quantity":"1" }, "pet": {"id":"pet", "type":"text", "name":"Owns pet", "quantity":"*" },
Code:
for (Record record : response.getData()) { for (String attribute : record.getAttributes()) { Record field = record.getAttributeAsRecord(attribute); addField(createField(field.getAttribute("id"), field.getAttribute("type"), field.getAttribute("name")); } } private DataSourceField createField(String id, String type, String name) { switch(FieldType.valueOf(type.toUpperCase())) { case TEXT: DataSourceField field = new DataSourceField(id, FieldType.TEXT, name); FormItem item = new RichTextItem(); field.setEditorType(item); return field; case DATETIME: //and so on } }
How can I achieve this? Thankful for any suggestions.
Comment