Reputation: 18786
I'm using Spring 3.0.5.
I've got a comma delimited string "A, B, C, D". Is it possible to build the list of options for a form:select input from this string?
I'm looking for something like:
<form:select path="foo.value" cssClass="formInput">
<form:options items="${myCommaString}"/>
</form:select>
or do I need to do a for each loop?
Upvotes: 0
Views: 2533
Reputation: 597124
BalusC is right - <form:options>
accepts a collection, map or array of objects. So use fn:split(..)
But in your case I'm not sure it will work. A select option needs two strings - a value (sent to the server on submission) and a display value (shown to users). Perhaps it will assume the same for both, so try it. If it doesn't work, you'll need the itemValue
and itemLabel
parameters.
Upvotes: 1
Reputation: 1108852
You can use JSTL fn:split()
to split a string on a delimiter into an array of substrings.
<form:options items="${fn:split(myCommaString, ', ')}" />
Upvotes: 2