Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring mvc spring mvc多值选择下拉列表。作为域对象的值。如何实现这一点_Spring Mvc_Dropdownbox - Fatal编程技术网

Spring mvc spring mvc多值选择下拉列表。作为域对象的值。如何实现这一点

Spring mvc spring mvc多值选择下拉列表。作为域对象的值。如何实现这一点,spring-mvc,dropdownbox,Spring Mvc,Dropdownbox,下面的代码用于单值选择,它工作得非常好。但当我将attribue multiple=true添加到form:select标记时,当我在Jsp中选择多个值时,save方法中的country对象参数的值为null。为了在controller方法中获得country对象的列表,我必须在jsp中做什么更改。请告知 JSP代码 国家和国家级 _________________________ 如果我将country变量转换为在country类中列出country。jsp和控制器方法应该如何更改 根据给定的

下面的代码用于单值选择,它工作得非常好。但当我将attribue multiple=true添加到form:select标记时,当我在Jsp中选择多个值时,save方法中的country对象参数的值为null。为了在controller方法中获得country对象的列表,我必须在jsp中做什么更改。请告知

JSP代码 国家和国家级 _________________________


如果我将country变量转换为在country类中列出country。jsp和控制器方法应该如何更改

根据给定的jsp,国家和州的模型Java类应如下所示

public class Country{
private List<State> stateList;
//getter and setters
}

/** State object**/
public class State{
    private long stateUniqueCode;
    private String stateName;
//getter and setters
}
您应该按如下方式在路径中绑定stateList属性

<form:form modelAttribute="country">    
<li>
    <form:label cssClass="mandatory" path="stateList">Select State</form:label>
        <form:select path="stateList" cssErrorClass="error">
             <form:option value="" label="Please Select..." />
                <c:forEach items="${listOfStates}" var="s">
                    <form:option value="${s.stateUniqueCode}" label="${s.stateName}"/>  
                </c:forEach>
        </form:select>
</li>
检查我的答案。也许对你有帮助
 /** Country object**/
    public class Country{
    private State state;
    //getter and setters
    }

    /** State object**/
    public class State{
        private long stateUniqueCode;
        private String stateName;
    //getter and setters
    }
public class Country{
private List<State> stateList;
//getter and setters
}

/** State object**/
public class State{
    private long stateUniqueCode;
    private String stateName;
//getter and setters
}
<form:form modelAttribute="country">    
<li>
    <form:label cssClass="mandatory" path="stateList">Select State</form:label>
        <form:select path="stateList" cssErrorClass="error">
             <form:option value="" label="Please Select..." />
                <c:forEach items="${listOfStates}" var="s">
                    <form:option value="${s.stateUniqueCode}" label="${s.stateName}"/>  
                </c:forEach>
        </form:select>
</li>