开发者

Springs 3, forms?? how do select option in dropdown (select box)?

I am writing a system in Springs 3 and everything works great on the inbox screens but on one of the input screens I have a dropdown box or a selectbox. I am trying to find a way that Springs will select the right option. Sometimes the user makes a error on the page or forgets to enter something and I redisplay the page but how do I make it select the right option. Below is the source code the the dropdown. It works for inbox great but how do I get it to select the right option on redisplay?

<form:select path="lst_mnt">
    <option value="1">January</option>
    <option value="2">February</option>
    <option value="3">March</option>
    <option value="4">April</option>
    <option value="5">May</option>
    <option value="6">June</option>
    <option value="7">July</option>
    <option value="8">August</option>
    <option value="9">September</option>
    <option value="10">October</option>
    <option value="11">November<开发者_Python百科;/option>
    <option value="12">December</option>
</form:select>


I use the items attribute of the spring form:select variable and it works fine.

<form:select path="lst_mnt" items="${myList}"/>

Perhaps you can put your list of months in an enum and access it from the controller like this:

@ModelAttribute("myList")
public static Month[] populateMyList() {
    return Month.values();
}

Hope that helps.

Edit:

You can also change your html option tags to springs options tags:

<form:option value="1">January</form:option>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜