Page 1 of 1
PropertyGroups - Select - multiple
PostPosted:Tue Sep 02, 2014 1:02 pm
by Catscratch
Hi,
regarding the
Wiki Page currently only simple select properties can be used.
Select
- type: Actually can be only "simple". Simple means that only one option can be selected at a time. Defaults to "simple".
I saw that openkm community 6.3 already supports multiple attributes for a select form. In the frontend you can add more than one values for a select type="multiple".
Unbenannt.PNG (2.08 KiB) Viewed 3557 times
So it seems only the REST endpoint and the SDK won't support this, because there you always only got key-value pairs (e.g. for setPropertyGroupPropertiesSimple) instead of key-list<value> pairs.
So my question is, do you have some kind of roadmap about when this feature will be available?
Thanks.
Re: PropertyGroups - Select - multiple
PostPosted:Fri Sep 05, 2014 6:28 am
by jllort
To select multiple values in select must use special character separator into a single string, the separator is ;
For example if you want to set two values 1,2 then the String in setPropertiesSimple should be "1;3"
Sincerally is not documented on wiki, we will add some note in REST SDK section
Re: PropertyGroups - Select - multiple
PostPosted:Fri Sep 05, 2014 9:36 am
by Catscratch
Thanks for reply, but it is not working.
Setting only one ID is working. E.g. ID1. Or setting only ID2.
But setting "ID1;ID2" is not working. The property remains empty.
Edit: I further investigated the problem. In PropertyGroupService.java you don't care about the ";".
Linie 199:
Code: Select allfor (Option opt : sel.getOptions()) {
if (opt.getValue().equals(value)) {
opt.setSelected(true);
} else {
opt.setSelected(false);
}
}
Edit2: I modified your code and now it is working.
Code: Select all} else if (fe instanceof Select) {
Select sel = (Select) fe;
// Check if there are multiple values in the value string separated by ';'
List<String> splitValues = Arrays.asList(value.split(";"));
for (Option opt : sel.getOptions()) {
if (splitValues.contains(opt.getValue())) {
opt.setSelected(true);
} else {
opt.setSelected(false);
}
}
}
But a better way would be to refactor the REST interface for not using a Map<String, String> but a Map<String, List<String>>.
Anyway, you can use my code if it helps.
Re: PropertyGroups - Select - multiple
PostPosted:Sat Sep 06, 2014 8:55 am
by jllort
It's a bug on this community version, I've upload today a patch. Try tomorrow the nighly build (integration.openkm.com).
Re: PropertyGroups - Select - multiple
PostPosted:Mon Sep 08, 2014 8:00 am
by Catscratch
I synchronized my own code with yours and yes, your solution is working too. Thanks!
One last hint: Instead of hardcoding
Code: Select allpublic static String LIST_SEPARATOR = ";";
in Config.java, you could push it to Configuration View in the admin panel.
Re: PropertyGroups - Select - multiple
PostPosted:Wed Sep 10, 2014 6:33 pm
by jllort
You talk about, create new configuration property to change default separator, is that ? I do not know if it's good idea because for example windows tools I think we're using ";" by default. If you see some advantage on be able to change it, we can consider your proposal.
Re: PropertyGroups - Select - multiple
PostPosted:Thu Sep 11, 2014 6:17 am
by Catscratch
Was just an idea. A better way would be to not use a separator and use another datatype (e.g. List<String>) instead. Doing this by a separator seems to only be a workaround.
Re: PropertyGroups - Select - multiple
PostPosted:Sat Sep 13, 2014 11:05 am
by jllort
The main idea was to do it as simply as possible, like the name indicates. Properties use a map of <String, String>, to follow your purpose should be serialized the list to string value ( json or similar ), for example with json ( we thought in past, the easiest serialization type was use character separator ). Also There's other method setProperties what take advantage of FormElement classes ( there are Select classes with option list ), the formal implementation ( but not very comfortable )