Reputation: 823
I am working with ExtJS 5.1.1 and getting an error during POST
process to Java server. Inside the DB there are several fields and ID
is keyfield and generate automatically by server. I need only 3 fields to display and create/update/delete; firstName, lastName, email. I can't configure the ExtJS for POST to not touch ID, only pass those three fields via Form Panel.
Here is Request Payload of one sample record. As you will notice it gave name of Model to ID
:
{"firstName":"New","lastName":"Record","email":"[email protected]","id":"Employee.model.EmployeeMdl-2"}
Therefore Java-Spring server response this message:
"Could not read document: Can not deserialize value of type int from String "Employee.model.EmployeeMdl-1": not a valid Integer value↵ at [Source: java.io.PushbackInputStream@ae6769; line: 1, column: 74]
The PUT
process works very well! Could you please give any idea for POST
?
Here is Model snippet:
Ext.define('Employee.model.EmployeeMdl', {
extend: 'Ext.data.Model',
fields: [
{name: 'firstName', type: 'string'},
{name: 'lastName', type: 'string'},
{name: 'email', type: 'string'}
],
idProperty: 'id',
proxy: {
type: 'ajax',
headers: {
'Content-Type': 'application/json'
},
api: {
read: 'http://ip:port/orest/employee',
create: 'http://ip:port/orest/employee',
update: 'http://ip:port/orest/employee'
},
reader: {
type: 'json'
},
writer: {
type: 'json',
allowSingle: true,
encode: false,
writeAllFields: true
}
}
});
Upvotes: 0
Views: 231
Reputation: 20224
You can provide to the model a specific way to generate the ID.
What I can recommend if integers are required is Ext.data.identifier.Negative
. You would put the full class name into the requires section of the model and then just add the config identifier: 'negative'
in the model.
Of course this means that you would have to tell the backend that negative ids indicate new entries.
Upvotes: 1