开发者

listing values in spring

I am doing following

List list=new ArrayList();
list.add(new String[] {"1","java"});
model.addAttribute("tagList", list);

And in view

<form:select path="probTag">
    <form:options items="${tagList}" itemLabel="${tagList[0]}" itemValue="${tagList[1]}"/>
</form:select>

but this is no开发者_开发百科t working. What else can be done to solve the problem ???


<form:options> can't work with arrays this way. Use either a class to encapsulate option

class Tag {
    public String id;
    public String name;

    public Tag(String id, String name) {
        this.id = id;
        this.name = name;
    }
}

-

list.add(new Tag("1","java")); 

-

<form:select path="probTag"> 
    <form:options items="${tagList}" itemLabel="name" itemValue="id" /> 
</form:select> 

or iterate over the options manually

<form:select path="probTag"> 
    <c:forEach var = "t" items = "${tagList}">
        <form:option value="${t[0]}">${t[1]}</form:option>
    </c:forEach> 
</form:select> 
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜