我有一個國家,州和城市下拉框的JSP。城市默認填充,然後州和城市將根據使用阿賈克斯選定的國家和州進行。彈出mvc綁定異常提交選擇框
<form:select path="ContactInfoVO[0].countryList" multiple="single" id="country">
<form:option value="-1" label="-- Select Country--"></form:option>
<c:forEach var="country" items="${ManagerVO.ContactInfoVO[0].countryList}" varStatus="item">
<form:option value="${country.countryId}" label="${country.countryName}"/></c:forEach> </form:select>
<form:select path="ContactInfoVO[0].stateList" multiple="single" id="state" class="small">
<form:option value="-1" label="-- Select State--"></form:option>
<c:forEach var="state" items="${ManagerVO.ContactInfoVO[0].stateList}" varStatus="item">
<form:option value="${state.stateId}" label="${state.stateName}"/></c:forEach></form:select>
<form:select path="ContactInfoVO[0].cityList" multiple="single" id="city" class="validate[required] small">
<form:option value="-1" label="-- Select City--"></form:option>
<c:forEach var="city" items="${ManagerVO.ContactInfoVO[0].cityList}" varStatus="item">
<form:option value="${city.cityId}" label="${city.cityName}"/></c:forEach></form:select>
當我提交此表,我得到的錯誤 -
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 3 errors
Field error in object 'ManagerVO' on field 'ContactInfoVO[0].cityList': rejected value [80930]; codes [typeMismatch.ManagerVO.ContactInfoVO[0].cityList,typeMismatch.ManagerVO.ContactInfoVO.cityList,typeMismatch.ContactInfoVO[0].cityList,typeMismatch.ContactInfoVO.cityList,typeMismatch.cityList,typeMismatch.java.util.List,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [ManagerVO.ContactInfoVO[0].cityList,ContactInfoVO[0].cityList]; arguments []; default message [ContactInfoVO[0].cityList]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.List' for property 'ContactInfoVO[0].cityList'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [com.admin.command.CityVO] for property 'cityList[0]': no matching editors or conversion strategy found]
Field error in object 'ManagerVO' on field 'ContactInfoVO[0].countryList': rejected value [31]; codes [typeMismatch.ManagerVO.ContactInfoVO[0].countryList,typeMismatch.ManagerVO.ContactInfoVO.countryList,typeMismatch.ContactInfoVO[0].countryList,typeMismatch.ContactInfoVO.countryList,typeMismatch.countryList,typeMismatch.java.util.List,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [ManagerVO.ContactInfoVO[0].countryList,ContactInfoVO[0].countryList]; arguments []; default message [ContactInfoVO[0].countryList]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.List' for property 'ContactInfoVO[0].countryList'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [com.admin.command.CountryVO] for property 'countryList[0]': no matching editors or conversion strategy found]
Field error in object 'ManagerVO' on field 'ContactInfoVO[0].stateList': rejected value [601]; codes [typeMismatch.ManagerVO.ContactInfoVO[0].stateList,typeMismatch.ManagerVO.ContactInfoVO.stateList,typeMismatch.ContactInfoVO[0].stateList,typeMismatch.ContactInfoVO.stateList,typeMismatch.stateList,typeMismatch.java.util.List,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [ManagerVO.ContactInfoVO[0].stateList,ContactInfoVO[0].stateList]; arguments []; default message [ContactInfoVO[0].stateList]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.List' for property 'ContactInfoVO[0].stateList'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [com.admin.command.StateVO] for property 'stateList[0]': no matching editors or conversion strategy found]
有人可以告訴我怎麼解決?
我只是試圖在狀態和國家的基礎上填充城市,在表單提交我將只使用cityId。所有三個字段(國家,州,城市)都有自己的主表,從中選擇框正在填充。現在,當我點擊提交時,彈簧在達到控制器之前就會引發此錯誤,這意味着模型屬性的綁定失敗。你可以給我一些建議,讓我可以在我的控制器上獲取cityId嗎? – Sachin
我認爲你需要改變'
謝謝,不知道我怎麼沒有注意到這個更早:(但這解決了這個問題 – Sachin