Reputation: 3160
I have a form with a text-input element.
The user can enter values separated by commas like "a,b,c,d". In my model, there's a List which should then hold these values (which really are a list).
In Thymeleaf, how can I bind such a string and convert it to a list on submit? Is there something like a Converter interface?
Upvotes: 2
Views: 2263
Reputation: 1550
In your Model instead of List you can use String to populate the input values. After you get the values, you can do following:
You will probably have a String something like this: "text1, text2, text3...". Then convert it to a List you can do something like this:
String value = "text1, text2, text3..."
List<String> inputs = Arrays.asList(value.split("\\s*,\\s*"));
The regex basically removes the whitespace and the comma. This should work fine.
Upvotes: 1