不要刷新失败

时间:2014-01-17 11:20:16

标签: javascript jquery jsp spring-mvc refresh

我有一个带有选择器和其他字段(输入)的表单的应用程序,我用spring-mvc(jsp,javascript)开发它,当选择器更改状态(值)时我遇到问题更改其他字段的值。在jsp页面中,我将一个列表传递给ModelMap,然后我必须检查选择器是否更改为使用其列表值检查此值,因为此处是其他字段的值。一些想法?

我的代码:

我的控制器

    ...
        @RequestMapping(value = "/addDevice", method = RequestMethod.GET)
            public String addShowDevice (ModelMap model, HttpSession session) throws Instantiation

Exception, IllegalAccessException
        {
            logger.info ("Entrando en add Device");
            ...

            DeviceObjects deviceObjects = new DeviceObjects ();

            //Only the admin can change all properties
            if(!profile.equals("admin")){
                model.addAttribute("hardwareDeviceTypeList", hardwareDeviceTypeBo.findAll());
            }
            model.addAttribute ("device", deviceObjects);
            return "addDevice";
        }
...

我的jsp文件

hardwareDeviceTypeList列表包含在modelMap中

<script type="text/javascript">
$(document).ready(function(){
   $("#model").on('change',function(){
        var valor = $(this).val();
        for(ind=0; ind<hardwareDeviceTypeList.length; ind++)
        {
            if (hardwareDeviceTypeList[ind].model == model){
                document.getElementById("maker").value = hardwareDeviceTypeList[ind].maker;
                document.getElementById("manufacturer").value = hardwareDeviceTypeList[ind].manufacturer;
                document.getElementById("vendor").value = hardwareDeviceTypeList[ind].vendor;
                document.getElementById("name").value = hardwareDeviceTypeList[ind].name;
                break;
            }
        }
        alert(valor);
        alert(deviceObjects.deviceObjects.length);
    });
...
});
</script>
....
            <td>
                <fmt:message key="common.model"/>
            </td>
            <td>
                <form:select path="model" >
                        <form:option value=""><fmt:message key="element.select"/></form:option>
                        <form:options items="${listModel}" />
                </form:select>
          ...
          <form:input type="text" name="manufacturer" id="manufacturer" readonly="readonly" size="12" path="manufacturer" />
          ...
          <form:input path="name"/>

0 个答案:

没有答案