从spring mvc设置selectbox值 [英] Setting a selectbox value from spring mvc

查看:205
本文介绍了从spring mvc设置selectbox值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在控制器的jsp中设置selectbox值。

How to set a selectbox value in jsp from controller.

Employee employee = new Employee();

我为实体员工创建新对象,然后设置$的值b $ b使用此代码进行指定..

I created new object for entity Employee and then set the value of designation with this code..

employee.setEmpDesignation(addEmployeeForm.getEmpDesignation());

这是jsp

<form:select path="empDesignation" id="emplDesignation" onchange="showTextBox();" cssClass="textBox">
    <c:forEach var="desig" items="${designation}">
        <option value="${desig.designationDesc}">
              <c:out value="${desig.designationDesc}"/>
        </option>
    </c:forEach>
</form:select>

基本上我在设置错误发生时设置用户输入的值。

Basically I am trying to set the values entered by the user,when error occurs.

但它总是显示选择框中的第一个值。

But it always displays the first value in the selectbox.

推荐答案

你为什么不使用< form:options>

例如:

<form:select path="empDesignation">
    <form:options items="${designation}" itemLabel="designationDesc" itemValue="designationDesc"/>
</form:select>

如果您的表单支持对象已绑定,SpringMVC应该为您处理所有这些。

if your form backing object is bound, SpringMVC should handle all this for you.

这篇关于从spring mvc设置selectbox值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆