Hello,
I try to combine Kendo UI with Struts 2 action. Until now the results to retrieve data from the DB are satisfactory.
The table is loaded correctly with the data retrieved from the Action. The problem starts when i try to delete
an entry.
Source code:
Inside my Struts 2 action i have getters and setters for the following variables:
-String text;
-String lang;
-String models;
Now i noticed the following behaviour:
First Scenario
When calling the deleteRow function in my struts action, the following parameters are send of the current row that i want to delete:
This is a copy of the url parameters: _=1353667421178
callback=jQuery17201980517354870166_1353667373995
models=[{"lang":"de","text":"ProjectRoot-System","uuid":"c0437761-1c29-11e2-892e-0800200c9a66"},{"lang":"de","text":"Stephan","uuid":"46baf7b1-2345-11e2-81c1-0800200c9a66"}]
Unfortunately as a response from the server i get the following error :
org.apache.struts2.json.JSONException: Input string is not well formed JSON (invalid char ?)
I try to combine Kendo UI with Struts 2 action. Until now the results to retrieve data from the DB are satisfactory.
The table is loaded correctly with the data retrieved from the Action. The problem starts when i try to delete
an entry.
Source code:
<script>
$(document).ready(
function
() {
var
crudServiceBaseUrl =
"http://demos.kendoui.com/service"
,
dataSource =
new
kendo.data.DataSource({
transport: {
read: {
dataType:
"json"
},
destroy: {
dataType:
"jsonp"
,
contentType:
"application/json; charset=utf-8"
},
parameterMap:
function
(options, operation) {
if
(operation !==
"read"
&& options.models) {
return
{models: kendo.stringify(options.models)};
}
}
},
batch:
true
,
pageSize: 30,
schema: {
data:
"myList"
,
model: {
id:
"uuid"
,
fields: {
uuid: { editable:
false
, nullable:
true
},
lang: { type:
"string"
},
text: { type:
"string"
}
}
}
}
});
$(
"#grid"
).kendoGrid({
dataSource: dataSource,
pageable:
true
,
height: 400,
toolbar: [
"create"
],
columns: [
{ field:
"lang"
, title:
"Language"
},
{ field:
"text"
, title:
"Text"
, width:
"150px"
},
{ command: [
"edit"
,
"destroy"
], title:
" "
, width:
"210px"
}],
editable:
"popup"
});
});
</script>
Inside my Struts 2 action i have getters and setters for the following variables:
-String text;
-String lang;
-String models;
Now i noticed the following behaviour:
First Scenario
When calling the deleteRow function in my struts action, the following parameters are send of the current row that i want to delete:
callback | jQuery17201980517354870166_1353667373995 |
models | [{"lang":"de","text":"ProjectRoot-System","uuid":"c0437761-1c29-11e2-892e-0800200c9a66"},{"lang":"de","text" :"Stephan","uuid":"46baf7b1-2345-11e2-81c1-0800200c9a66"}] |
This is a copy of the url parameters: _=1353667421178
callback=jQuery17201980517354870166_1353667373995
models=[{"lang":"de","text":"ProjectRoot-System","uuid":"c0437761-1c29-11e2-892e-0800200c9a66"},{"lang":"de","text":"Stephan","uuid":"46baf7b1-2345-11e2-81c1-0800200c9a66"}]
Unfortunately as a response from the server i get the following error :
org.apache.struts2.json.JSONException: Input string is not well formed JSON (invalid char ?)
org.apache.struts2.json.JSONReader.buildInvalidInputException(JSONReader.java:155)
I did a debugging on the JSONInterceptor and found out that the json variable when trying to do the deserialize
Object obj = JSONUtil.deserialize(request.getReader());
the json variable is an empty string. Thus the above error.
Second Scenario
Instead of calling a function to delete, i changed that to call an action. When doing this, the action
is called and my String models variable is set with the following values [{"lang":"de","text":"ProjectRoot-System","uuid":"c0437761-1c29-11e2-892e-0800200c9a66"}].
This seems sort of correct. Unfortunately with this case, the whole process does not go through the
JSONInterceptor, so no deserialization is happening.
So what is my goal:
To be able when pressing on delete to call the delete function and set the object with the values that are
sent from kendo in order to continue with my own business logic process. What could be wrong
in my first scenario ?
Please let me know if you need further information.
Regards
Stephan