views:

28

answers:

1

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 not working. What else can be done to solve the problem ???

+1  A: 

<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> 
axtavt
thanks for your response did the same and got my solution thank your very much