Spring mvc form tag选择不显示选项列表

时间:2015-07-22 06:33:00

标签: java spring jsp spring-mvc

我有两个表MtMetalMtFomula的数据库。 MtMetal的字段lossFormula的类型为MtFomula。我想在从select表生成的列表中捕获类型为MtMetal的对象时,使用表单标记MtFormula来获取jsp中的丢失公式。不知何故,我无法将从数据库生成的列表传递给JSP form:select标记。下面是我的控制器中的方法,它可以用来调用JSP和JSP

@RequestMapping(value = "/inputmetal.html", method=RequestMethod.GET)
public ModelAndView metalInputForm(){

    MtFormula mtFormula = new MtFormula();
    List<MtFormula> formulaList=  mtFormulaService.getAll(mtFormula);
    ModelAndView model=new ModelAndView("metalinput");  
    model.addObject(formulaList);
    model.addObject("MtMetal", new MtMetal());
    return model;
}

JSP

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>

 <form:form modelAttribute="MtMetal" method="post" action="/labcontrol     /createmetal.html">
                <c:if test="${param.success eq true}">Metal save - Successful</c:if>
                <table border=1>
                    <tr>
                        <th>Metal details entry form</th>
                    </tr>
                    <tr>
                        <td>Metal Code1</td>
                        <td>
                            <input type=text name="metalCode" />
                        </td>
                    </tr>
                    <tr>
                        <td>Metal Description</td>
                        <td>
                            <input type=text name="metalDesc" />
                        </td>
                    </tr>
                    <tr>
                        <td>Metal Unit of measure</td>
                        <td>
                            <input type=text name="metalUnit" />
                        </td>
                    </tr>
                    <tr>
                        <td>Loss Formula</td>
                        <td>
                            <form:select path="lossFormula">
                                <form:option value="-" label="--Please Select" />
                                <form:options items="${formulaList}" itemValue="formulaCode" itemLabel="FormulaDesc" /></form:select>
                        </td>
                    </tr>
                    <tr>
                        <td>Treatment recovery</td>
                        <td>
                            <input type=number name="treatmentRecovery" />
                        </td>
                    </tr>
                    <tr>
                        <td>Salable mass</td>
                        <td>
                            <input type=number name="saleableMass" />
                        </td>
                    </tr>
                    <tr>
                        <td>Pricing unit</td>
                        <td>
                            <input type=number name="pricePerUnit" />
                        </td>
                    </tr>
                    <tr>
                        <td>Gross value</td>
                        <td>
                            <input type=number name="grossValue" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <input type="submit" value="Save record">
                        </td>
                    </tr>
                </table>
            </form:form>

0 个答案:

没有答案