2012-10-16 24 views
0

我在向弹簧控制器发布选择框数据时遇到了一个问题。转换为字符串的弹簧通用转换器问题

<form:select path="ContactInfoVO[0].cityId" 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> 

Spring的通用转换服务正在实际值之前添加','。看着日志我看到以下 -

23:00:45,511 DEBUG BeanWrapperImpl:579 - Using cached nested BeanWrapper for property 'restaurantContactInfoVO[0]' 
23:00:45,512 DEBUG GenericConversionService:139 - Checking if I can convert java.lang.String[] to java.lang.String 
23:00:45,516 DEBUG GenericConversionService:358 - Searching for converters indexed by sourceType [[Ljava.lang.String;] 
23:00:45,517 DEBUG GenericConversionService:429 - and indexed by targetType [java.lang.String] 
23:00:45,519 DEBUG GenericConversionService:429 - and indexed by targetType [java.io.Serializable] 
23:00:45,520 DEBUG GenericConversionService:429 - and indexed by targetType [java.lang.Comparable] 
23:00:45,521 DEBUG GenericConversionService:429 - and indexed by targetType [java.lang.CharSequence] 
23:00:45,523 DEBUG GenericConversionService:429 - and indexed by targetType [java.lang.Object] 
23:00:45,524 DEBUG GenericConversionService:358 - Searching for converters indexed by sourceType [[Ljava.lang.Object;] 
23:00:45,527 DEBUG GenericConversionService:429 - and indexed by targetType [java.lang.String] 
23:00:45,528 DEBUG GenericConversionService:473 - Found matchable converters [email protected]ba3bff5 
23:00:45,530 DEBUG GenericConversionService:560 - Matching [email protected]ba3bff5 
23:00:45,531 DEBUG GenericConversionService:139 - Checking if I can convert java.lang.String to java.lang.String 
23:00:45,532 DEBUG GenericConversionService:246 - Matched cached converter o[email protected]6f69b66e 
23:00:45,534 DEBUG GenericConversionService:147 - Yes, I can convert 
23:00:45,535 DEBUG GenericConversionService:564 - Matched converter [email protected]ba3bff5 
23:00:45,536 DEBUG GenericConversionService:254 - Caching under ConverterCacheKey [sourceType = java.lang.String[], targetType = java.lang.String] 
23:00:45,537 DEBUG GenericConversionService:147 - Yes, I can convert 
23:00:45,539 DEBUG GenericConversionService:159 - Converting value array<String>['', '145009'] of java.lang.String[] to java.lang.String 
23:00:45,542 DEBUG GenericConversionService:246 - Matched cached converter [email protected]ba3bff5 
23:00:45,544 DEBUG GenericConversionService:159 - Converting value '' of java.lang.String to java.lang.String 
23:00:45,545 DEBUG GenericConversionService:246 - Matched cached converter o[email protected]6f69b66e 
23:00:45,546 DEBUG GenericConversionService:186 - Converted to '' 
23:00:45,548 DEBUG GenericConversionService:159 - Converting value '145009' of java.lang.String to java.lang.String 
23:00:45,551 DEBUG GenericConversionService:246 - Matched cached converter o[email protected]6f69b66e 
23:00:45,552 DEBUG GenericConversionService:186 - Converted to '145009' 
23:00:45,554 DEBUG GenericConversionService:186 - Converted to ',145009' 

我有一个更多的选择框和两个代码是相同的(几乎)。我仍然不知道为什么春天把这一个当作String []而不是String。有人能对此有所了解吗?

+2

如果您在触发控制器时查看原始请求参数,则可能会看到该参数有两个实例(有问题)。一个将有145009的价值,另一个将是空的。这就是为什么你看到一个String []而不是String的原因。你需要弄清楚为什么这个参数被设置了两次。是否有一个隐藏的字段具有相同的'名称'或第二个输入的名称相同?看看HTML源代码,而不是你的JSP来检查它。 – nickdos

+0

是的,只是注意到相同的参数被用在没有填充的隐藏文本框中。谢谢。 – Sachin

回答

0

另外一个参数与形式相同的id导致此问题。现在修复。