X-editable プラグインを使用して、複数のフィールドとデータ型でフォームを更新しています。フォームの各要素にはname
、DTO 内の Java 属性をマップする値があります。フォームが送信されると、Ajax を使用して、すべての値が Java オブジェクトの対応するフィールドと一致しますが、 TAGS 配列は理論的には文字列のリストと一致するはずですが、どういうわけかNumberFormatException
.
スタックトレース
[Request processing failed; nested exception is java.lang.NumberFormatException: For input string: ""] with root cause
java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:991)
Select2 タグモード
$('.issue-tags').editable({
pk: 22,
name: 'tags',
placement: 'top',
mode: 'popup',
select2: {
tags: ${tags},
tokenSeparators: [",", " "]
},
ajaxOptions: {
type: 'put'
}
});
「tags」プロパティは、データベースから値をロードします。
送信ボタン
$('#btn-submit').click(function() {
$('.editable').editable('submit', {
url: './updateForm.html',
ajaxOptions: {
dataType: 'json'
},
success: function(data, config) {
...
},
error: function(errors) {
...
}
});
});
Java DTO
public class MyObjectDTO implements Serializable {
private List<String> tags = new ArrayList<String>();
...
}
Spring MVC コントローラー
@RequestMapping(value="/updateForm", method = RequestMethod.POST)
public @ResponseBody String doUpdateForm(@ModelAttribute("object") MyObjectDTO object,
HttpServletRequest request) throws ParseException{
...
}
タグ フィールドがない場合、フォームはデータをコントローラーに正しく送信します。