开发者

spring binding formmultiselect

开发者 https://www.devze.com 2022-12-22 11:20 出处:网络
I\'m trying to bind multiselect to my object. The form is created and the post works and no errors occur when I don\'t select anything. If I select a language the object gets language value but the fo

I'm trying to bind multiselect to my object. The form is created and the post works and no errors occur when I don't select anything. If I select a language the object gets language value but the form breaks.

        HashMap<String, String> languages = new LinkedHashMap<String, String>();
    languages.put("eng","english");
    languages.put("ger","german"); 

    session.setAttribute("languages", languages);

<@spring.formMultiSelect "advancedSearch.languages", languages, " "/>

AdvancedSearch class has

String languages;

and it gets a value "eng, rus" but the form doesn`t work after it gets a value.

Error message

HTTP ERROR 500

Problem accessing 开发者_开发问答/opac/advSearch. Reason:

Expected collection or sequence. list evaluated instead to

freemarker.template.SimpleScalar on line 368, column 12 in spring.ftl. Caused by:

Expected collection or sequence. list evaluated instead to freemarker.template.SimpleScalar on line 368, column 12 in spring.ftl. The

problematic instruction:

==> list list as nextInList [on line 368, column 5 in spring.ftl] in user-directive spring.formMultiSelect [on line 59, column 41 in advancedSearchView.ftl]

I think the problem is with the way I save languages. Right now it`s String. I guess I need to hold it some other way. I tried String[] List but can't get things to work.


<@spring.bind "advancedSearch.languages"/>
<#assign selectedLangs = spring.status.value?default(" ")>
<select multiple="multiple" id="${spring.status.expression}" name="${spring.status.expression}"}>
    <#list languages?keys as value>
    <#if selectedLangs?contains(value) >
        <#assign isSelected = true>
    <#else>
        <#assign isSelected = false>
    </#if>
    <option value="${value?html}"<#if isSelected> selected="selected"</#if>>${languages[value]?html}
    </#list>
</select>

This worked!

0

精彩评论

暂无评论...
验证码 换一张
取 消