編輯:的Spring Portlet jQuery的阿賈克斯後到控制器
的開始日期和結束日期是喬達日期時間的POJO和我得到的錯誤是:
SystemOut O 14:10:16.040 [WebContainer : 2] DEBUG org.springframework.beans.BeanUtils - No property editor [org.joda.time.DateTimeEditor] found for type org.joda.time.DateTime according to 'Editor' suffix convention
...
SystemOut O Error::Failed to convert property value of type 'java.lang.String' to required type 'org.joda.time.DateTime' for property 'startTimestamp'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.joda.time.DateTime] for property 'startTimestamp': no matching editors or conversion strategy found
我也不能編輯這個POJO並添加@DateTimeFormat,因爲Pojos是從XSD生成的。我也嘗試添加一個customObjectMapper,但沒有任何工作。任何幫助將非常感激。
原題:
我試圖提交表單和數據發送到控制器方法。問題是ModelAttribute是空的並且沒有值。 Spring MVC中的Portlet + JSP + JavaScript和jQuery的+控制器@ResourceMapping
段:
JSP:
<portlet:resourceURL id="addNewURL" var="addNewURL">
</portlet:resourceURL>
<form:form id="qmat_new_notification_form" action="#" method="POST" modelAttribute="dataObject">
...
<input type="text" class="date-picker" id="start_date">
...
<input type="submit" value="Save" class="button" onclick="addNew()">
</form:form>
的Jquery:
function addNew() {
var dataObject = JSON.stringify({
'startTime': $('#start_date').val(),
'endTime': $('#end_date').val(),
'description': $('#message').val(),
'active': $('#status').val()
});
alert("data::"+dataObject);
$.ajax({
url: "<%=addNewURL%>",
type: 'POST',
contentType: 'application/json',
data: dataObject
}).done(function(json){
alert("Success!");
//more logic
}).fail(function() {
alert("OOPS!");
});
}
控制器:
@ResourceMapping(value = "addNewURL")
public void addNew(@ModelAttribute(value = "dataObject") Obj n,
BindingResult bindingResult, ResourceRequest request, ResourceResponse response, ModelMap model) {
if (!bindingResult.hasErrors()) {
System.out.println("a:::"+n.getDescription());
}
此getDescription爲null。另外如果我使用request.getParameter(「description」)也是null。我錯過了什麼?請幫助
哪個入口? Liferay 6.2? –
Websphere Portal Server 7.0.0.2。感謝您的詢問 – Harry