PDA

View Full Version : Cannot read property "fields" of undefined



bomslang
4 Sep 2012, 10:18 AM
Folks,

I am trying to bind my model with store using REST proxy as shown here

http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.Model

Here's my code inside launch( ) function :-



launch: function() {

Ext.define('Record', {
extend: 'Ext.data.Model',
fields: [{name: 'id', type:'int'}, {name:'content', type:'string'} ,{name: 'name', type:'string'} ,{name:'title', type:'string'}],
proxy: {
type: 'rest',
api: {
read : 'feedback/read.action',
create : 'feedback/new.action',
update: 'feedback/update.action',
destroy: 'feedback/delete.action'
},
reader: {
type: 'json',
root: 'data',
totalProperty: 'total',
successProperty: 'success',
idProperty: 'id'
},
writer: {
type: 'json',
encode: true,
writeAllFields: true
}
}
});

var record = Ext.create('Record', {content:'ABC', name: 'XYZ', title: 'Title Text'});
var store = new Ext.data.Store({
model: record,
autoSave: false,
autoLoad: true
});




But it throws me below errors saying


Uncaught TypeError: Cannot read property 'fields' of undefined


38465

jay@moduscreate.com
4 Sep 2012, 10:22 AM
Model needs to be the Namespace of a constructor OR a reference to the constructor itself!

replace
model: record,
with
model: 'Record'

bomslang
4 Sep 2012, 10:51 AM
Thanks Jay.

That was helpful.

But minor problem I am facing is that -

I can now see the form values being appeared on grid panel. But those values aren't persisted in the database. I can't see them in DB.

It also throws me below exception ;-


POST http://localhost:8080/app/feedback/new.action?_dc=1346784472834 (http://localhost:8080/faq/feedback/newFeedback.action?_dc=1346784472834) 415 (Unsupported Media Type)



FYI, This is my server side code


@RequestMapping(value="/new.action", method=RequestMethod.POST)
public @ResponseBody Map<String,? extends Object> create(@RequestBody Object data) throws Exception {
try{
List<Feedback> feedbacks = feedbackService.create(data);
return getMap(feedbacks);
} catch (Exception e) {
return getModelMapError("Error trying to create Feedback.");
}
}


Why is this happening ?

jay@moduscreate.com
4 Sep 2012, 10:52 AM
Dude. You're back to where you have been for over a week!

Bring things down to simple terms. Make a simple form, submit it via POST. do you get the same error!?

your server side code is not correct.

bomslang
4 Sep 2012, 10:59 AM
I checked with this simple HTML form POST for that REST url.

It throws me below error on chrome window


Type Status report
message Request method 'POST' not supported
description The specified HTTP method is not allowed for the requested resource (Request method 'POST' not supported).


Should I try it by setting it to RequestMethod.PUT on server side ?