ExtJS 4.2 - Internal Server Error 500 When Loading Store - extjs

I keep on getting an internal server 500 error every time I attempt to load my store. I am currently trying to connect to our API endpoint that contains the data that I need. This is the error I'm getting every time (FYI, checking the 'Accept' Header, it seems it's empty. I am not sure how I can have an application/json there to correctly connect to it):
My Store is setup like this:
Ext.define('EcommBackoffice.store.TierCapacity', {
extend: 'Ext.data.Store',
model: 'EcommBackoffice.model.TierCapacityModel',
storeId: 'tier-capacity-id',
autoLoad: true,
sorters: [{
property: 'name',
direction: 'ASC'
}],
proxy: {
type: 'rest',
url: EcommBackoffice.Global.getAPIEndPoints().tier_capacity + '?siteCode=bgp88',
reader: {
type: 'json',
root: ''
},
listeners: {
exception: function(proxy, response, op) {
if (response.status === 403 || response.status === 401) return; /*skip this exception handler and check App exception handler*/
Ext.Msg.alert('ERROR', response.responseText + ' ' + response.statusText);
}
}
}
});
And my model like this:
Ext.define('EcommBackoffice.model.TierCapacityModel', {
extend: 'Ext.data.Model',
fields: [{
name: 'id'
}, {
name: 'paymentOption',
type: Ext.data.SortTypes.asUCString
}, {
name: 'tier',
type: Ext.data.SortTypes.asUCString
}, {
name: 'media',
type: Ext.data.SortTypes.asUCString
}, {
name: 'channels',
type: Ext.data.SortTypes.asUCString
}]
});
The API contains something like this:
[{
"name": "DEBIT",
"tiers": [{
"name": "Default",
"media": [{
"name": "OFFICE",
"channels": [{
"name": "CHANNEL-001",
"currentVolume": 0,
"maxVolume": 0,
"yesterdayVolume": 0
}]
}]
}]
}]
Moreover, I am a bit unfamiliar with setting up the models and stores. I am assuming that is where I'm missing something. Am I structuring the model correctly based on the API response? I tried reading the docs, but I still can't wrap my head around it.

Error Code 500 tells :
The server encountered an unexpected condition which prevented it from fulfilling the request.
As I can see that while processing code at your Java end , you are getting NullPointerException .
So when an unexpected exception occurs , Http 500 error code is thrown which is shown on your browser. This error code has nothing to be done from client side.

The error 500 is not an ExtJS issue. It's a backend issue. You should check what backend technologies you use and add these to the tags to get any help.
checking the 'Accept' Header, it seems it's empty. I am not sure how I can have an application/json there to correctly connect to it)
proxy: {
headers: {
Accept: 'application/json'
},

Related

SOAP web services client with ExtJS, SOAP and JavaScript

I implemented SOAP web services with WildFly. Invocation of endpoint interface is successful. The below url returns the correct result.
http://localhost:8080/SOAPJaxbWeb/?operation=ICallMemberPort
But the ExtJS soap client does not work at all. These are my ExtJS soap client codes.
Ext.define('Member', {
extend: 'Ext.data.Model',
fields : [{
name : 'id',
type : 'string'
}, {
name : 'passwd',
type : 'string'
}, {
name : 'age',
type : 'int'
}, {
name : 'name',
type : 'string'
}]
});
Ext.onReady(function () {
var family = Ext.create('Ext.data.Store' , {
model : 'Member',
autoLoad : true,
proxy: {
type: 'soap',
url: 'SOAPJaxbWeb/',
api: {
read: 'ICallMemberPort'
},
soapAction: {
read: 'http://localhost:8080/SOAPJaxbWeb/?operation=ICallMemberPort'
},
operationParam: 'ICallMemberPort',
targetNamespace: 'http://www.aaa.com/',
reader: {
type: 'soap',
record: 'ns|return',
namespace: 'ns'
},
exception: function(proxy, response, operation){
Ext.MessageBox.show({
title: 'REMOTE EXCEPTION',
msg: operation.getError(),
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
});
}
},
listeners: {
load: function(family, operation, success) {
if(success) {
alert('response : ' + family.model.length)
} else {
alert('it failed')
}
}
}
});
var onButtonClick = function() {
Ext.Msg.alert(Ext.getCmp('myid').getValue())
family.load()
};
I am afraid above ExtJS soap configuration is wrong. When executed, nothing shows.
proxy: soap
Note: This functionality is only available with the purchase of Sencha Complete. For more information about using this class, please visit our Sencha Complete product page.
https://docs.sencha.com/extjs/6.0/6.0.1-classic/#!/api/Ext.data.soap.Proxy

Sencha Touch 2.3 and Extjs 4.2

I am using Sencha Touch 2.3 and Extjs 4.2
Issue: Handle multiple root nodes JSON response(from single response) in multiple stores.
{
total:
[
{
exp_amount_tot: "71962.00",
income_amount_tot: "462129.00"
}
],
data:
[
{
id: "1",
userid: "2",
name: "Any",
notes: "",
},
]
}
I need to save the above response into two different stores.
1. dataStore rootproperty:"data"
2. summaryStore rootProperty: "total"
Please help me to fix this issue.
Store:
proxy: {
type: "ajax",
api: {
create: "http://localhost/api/getAccounts.php/create",
read: "http://localhost/api/getAccounts.php/getall",
update: "http://localhost/api/getAccounts.php/update",
},
reader: {
type: "json",
successProperty: 'success',
rootProperty: 'data',
messageProperty: 'message'
},
},
you can create 2 different stores with "data" & "total" root properties respectively and use the store.add() method to add the data to individual store.

The URL of an ajax proxy - Ext JS

I have a couple of questions about the url field of an ajax proxy, and Ext.Ajax.request
I'm getting a JSON response from an Ext.Ajax.request, and sending that data to a store. (I'm also trying to use the pagingToolbar, which is highly uncooperative at the moment)
Anyhow, the paging only seems to slightly work when I use an ajax proxy, however I'm not sure what to put in as the URL. Currently it's url: ''
var store = Ext.create('Ext.data.Store', {
storeId : 'resultsetstore',
autoLoad : false,
pageSize : itemsPerPage,
fields: [
{name : 'id', type : 'auto'},
{name : 'name', type : 'auto'},
{name : 'description', type : 'auto'}
],
proxy: {
type : 'ajax',
url : '???',
reader: {
type : 'json',
root : 'elements'
}
}
});
It seems the url reads data from a .json file in a specific directory (i.e. url: 'myData/data.json'), but there isn't any file like that to read from, as my response is coming back as a JSON Object.
And here is my request/response, which I parse and send to my store:
var request = Ext.Ajax.request({
url : 'MCApp', //here I specify the Servlet to be read from
jsonData : searchquery, //A JSON Object
params:{
start:0,
limit: itemsPerPage
},
success : function(response) {
mainresponse = response.responseText;
//etc.
}
Is having a separate request redundant?
Could I accomplish this within my store alone (passing my searchquery as a parameter to the server and all that jazz)?
I apologize for this jumbled question in advance!
Cheers
You can use a memory proxy and set the store data with the data property, but I don't recommend that.
If I where you I would forget the ajax request and start take advantage of the store's proxy.
Here's an example
var store = Ext.create('Ext.data.Store', {
storeId: 'resultsetstore',
autoLoad: false,
pageSize: 20,
fields: ['id','name','description'],
proxy: {
type: 'ajax',
url: 'urlToTheServlet', //here I specify the Servlet to be read from
extraParams: {
searchquery: 'Test'
}, //A String Object
reader: {
type: 'json',
root: 'elements'
}
}
});
store.load();
note that the start, limit are dealt with in the background. You don't have to set them manually. You can set a pageSize but it has it's own default, so it's not required.
This is what your data is expected to look like:
{
"elements": [
{
"id": 1,
"name": "John",
"description": "Project Manager"
},
{
"id": 2,
"name": "Marie",
"description": "Developer"
},
{
"id": 3,
"name": "Tom",
"description": "Technical Lead"
}
]
}
UPDATE: Passing an object as payload to the proxy
I had the same issue and I couldn't find an out of the box solution so I wrote my own proxy to resolve this.
Ext.define('BCS.data.proxy.AjaxWithPayload', {
extend: 'Ext.data.proxy.Ajax' ,
alias: 'proxy.ajaxwithpayload',
actionMethods: {
create: "POST",
destroy: "POST",
read: "POST",
update: "POST"
},
buildRequest: function(operation) {
var me = this,
request = me.callParent([operation]);
request.jsonData = me.jsonData;
return request;
}
});
Now you can do this:
var store = Ext.create('Ext.data.Store', {
storeId: 'resultsetstore',
autoLoad: false,
pageSize: 20,
fields: ['id','name','description'],
proxy: {
type: 'ajaxwithpayload',
url: 'urlToTheServlet', //here I specify the Servlet to be read from
jsonData : YOUR_OBJECT
reader: {
type: 'json',
root: 'elements'
}
}
});
I prefer to keep each method in a separated endpoint:
proxy: {
type: 'ajax',
reader: {
type: 'json'
},
api: {
read: 'getCenarioTreeNode', // To request a node children (expand a node)
create: 'createCenarioTreeNode', // When you insert a node
update: 'updateCenarioTreeNode', // When you change a node attribute
destroy: 'destroyCenarioTreeNode' // When you delete a node
},
writer: {
type:'json',
encode:true,
rootProperty:'data'
}
},

Synchronously loading 'MyApp.store.TreeStructures'; consider adding Ext.require('MyApp.store.TreeStructures') above Ext.onReady

Below, you will see that I'm getting a JavaScript exception with an MVC view I created in an Sencha ExtJS MVC application. I have another MVC view that extends 'Ext.tree.Panel' that reads a simple JSON object instead of pulling the data via an Ext.Direct proxy and .NET server-side stack, but the only thing that's different is the proxy implementation and of course our MVC controller logic. In the static (JSON) implementation, our proxy is defined in the model. In the dynamic (Ext.Direct) implementation, our proxy is defined in the store. The TreeStructures.js (store) JavaScript file keeps being requested an infinite amount of times until the browser crashes. See below for that exception.
I highly doubt this is an Ext.Direct issue because I have other stores working great with this architecture. I see the [Ext.Loader] exception, but I'm not sure why that one keeps repeating with every new TreeStructures.js request. Or where to implement that requires. My understanding is that the app.js defines the controllers. The controller then defines the models an stores. And the Viewport defines and instantiates other MVC views. My "other views" being the tree views. And the view implements the store.
Also, the Sencha Cmd "sencha app build" command is not working. Normally my application compiles without any issues, so something is definitely missing in the store or MVC configuration that's necessary for this dynamic tree.
Exception in JavaScript Console:
[Ext.Loader] Synchronously loading 'MyApp.store.TreeStructures'; consider adding Ext.require('MyApp.store.TreeStructures') above Ext.onReady
Browser crashes with this JavaScript Exception:
Note: The TreeStructures.js (store) JavaScript file keeps being requested an infinite amount of times until the browser crashes with this:
Uncaught RangeError: Maximum call stack size exceeded
Sencha Cmd errors (after calling the "sencha app build" command):
[ERR] failed to find meta class definition for name MyApp.store.TreeStructures
[ERR] def was null
[ERR] C2008: Requirement had no matching files <MyApp.store.TreeStructures> -- unknown-file:-1
Static tree implementation (reads JSON object to get data):
Ext.define('MyApp.store.Categories', {
extend : 'Ext.data.TreeStore',
model : 'MyApp.model.Category',
autoLoad : true,
root : {
text : 'All',
alias : '',
expanded : true
}
});
Ext.define('MyApp.model.Category', {
extend: 'Ext.data.Model',
fields: [
{ name: 'alias', type: 'auto' },
{ name: 'text', type: 'auto' }
],
proxy: {
type: 'ajax',
url: 'data/categories.json'
}
});
Ext.define('MyApp.controller.ConceptTreeReadonly', {
extend : 'Ext.app.Controller',
stores: ['Categories'],
models: ['Category'],
refs : [{
ref: 'categories',
selector: 'view-west'
}],
});
Dynamic tree implementation (uses server-side stack to get data):
Ext.create('MyApp.store.TreeStructures', {
extend: 'Ext.data.TreeStore',
model : 'MyApp.model.TreeStructure',
proxy: {
type: 'direct',
directFn: Concept_Tree_Structure.read,
reader: {
root: 'data'
}
},
root: {
text: 'Concept Tree',
id: 'root',
expanded: false
//children: []
},
autoLoad: false
});
Ext.define('MyApp.model.TreeStructure', {
extend: 'Ext.data.Model',
xtype: 'model-tree-structure',
fields: [
{ name: 'text' }, // string
{ name: 'id' }, // Int32 type: 'int'
{ name: 'expanded' }, // boolean
{ name: 'leaf' }, // boolean
{ name: 'children' } // List<TreeStructure>
]
});
Ext.define('MyApp.controller.ConceptTreeController', {
extend : 'Ext.app.Controller',
stores: ['TreeStructures', 'Concepts'],
models: ['TreeStructure', 'Concept'],
refs : [{
ref: 'concept-tree',
selector: 'view-concept-tree'
}],
init : function() {
this.getConceptsStore().load({
params: {
start: 0,
limit: 10,
foo: 'bar'
}
});
this.getTreeStructuresStore().load({
params: {
start: 0,
limit: 10,
foo: 'bar'
}
});
}
});
Change Ext.create('MyApp.store.TreeStructures'...
To Ext.define('MyApp.store.TreeStructures'...

Ext.data.LocalStorage not working on Offline Mode

Im now studying Sencha Touch 2 and doing some Research on Ext.data.LocalStorage that can be use in Offline Mode.
I tried to follow this turorial
Sencha Touch 2 Local Storage
and just updated the code from Github - RobK/SenchaTouch2-LocalStorageExample or riyaadmiller/LocalStorage and modified Store url using my own WCF Rest
but i cant get LocalStorage working on offline mode.I have no issue on running the app Online. I also tried to debug it on Chrome developer tool but LocalStorage always get 0 data. I used Chrome/Safari Browser and also build the apps as Android using Phonegap build and still not working.
Did I miss something?
Does anyone can provide the details to deal with this Issue.
Below is my code:
Store:
Ext.define('Local.store.News', {
extend:'Ext.data.Store',
config:{
model: 'Local.model.Online',
proxy:
{
type: 'ajax',
extraParams: { //set your parameters here
LookupType: "Phone",
LookupName: ""
},
url: 'MY WCF REST URL',
headers: {
'Content-Type': 'application/json; charset=utf-8'
},
reader:
{
type: 'json'
, totalProperty: "total"
},
writer: { //Use to pass your parameters to WCF
encodeRequest: true,
type: 'json'
}
},
autoLoad: true
}
});
Offline Model:
Ext.define('Local.model.Offline', {
extend: 'Ext.data.Model',
config: {
idProperty: "ID", //erm, primary key
fields: [
{ name: "ID", type: "integer" }, //need an id field else model.phantom won't work correctly
{ name: "LookupName", type: "string" },
{ name: "LookupDescription", type: "string" }
],
identifier:'uuid', // IMPORTANT, needed to avoid console warnings!
proxy: {
type: 'localstorage',
id : 'news'
}
}
});
Online Model:
Ext.define('Local.model.Online', {
extend: 'Ext.data.Model',
config: {
idProperty: "ID", //erm, primary key
fields: [
{ name: "ID", type: "integer" }, //need an id field else model.phantom won't work correctly
{ name: "Name", type: "string" },
{ name: "Description", type: "string" }
]
}
});
Controller:
Ext.define('Local.controller.Core', {
extend : 'Ext.app.Controller',
config : {
refs : {
newsList : '#newsList'
}
},
/**
* Sencha Touch always calls this function as part of the bootstrap process
*/
init : function () {
var onlineStore = Ext.getStore('News'),
localStore = Ext.create('Ext.data.Store', { storeid: "LocalNews",
model: "Local.model.Offline"
}),
me = this;
localStore.load();
/*
* When app is online, store all the records to HTML5 local storage.
* This will be used as a fallback if app is offline more
*/
onlineStore.on('refresh', function (store, records) {
// Get rid of old records, so store can be repopulated with latest details
localStore.getProxy().clear();
store.each(function(record) {
var rec = {
name : record.data.name + ' (from localStorage)' // in a real app you would not update a real field like this!
};
localStore.add(rec);
localStore.sync();
});
});
/*
* If app is offline a Proxy exception will be thrown. If that happens then use
* the fallback / local stoage store instead
*/
onlineStore.getProxy().on('exception', function () {
me.getNewsList().setStore(localStore); //rebind the view to the local store
localStore.load(); // This causes the "loading" mask to disappear
Ext.Msg.alert('Notice', 'You are in offline mode', Ext.emptyFn); //alert the user that they are in offline mode
});
}
});
View:
Ext.define('Local.view.Main', {
extend : 'Ext.List',
config : {
id : 'newsList',
store : 'News',
disableSelection : false,
itemTpl : Ext.create('Ext.XTemplate',
'{Name}-{Description}'
),
items : {
docked : 'top',
xtype : 'titlebar',
title : 'Local Storage List'
}
}
});
Thanks and Regards
1) First of all when you creating record and adding into store, the record fields should match the model fields of that store.
Here you creating record with field name, but Local.model.Offline didn't name field
var rec = {
name : record.data.name + ' (from localStorage)'
};
This is what you need to do within refresh
localStore.getProxy().clear();
// Also remove all existing records from store before adding
localStore.removeAll();
store.each(function(record) {
console.log(record);
var rec = {
ID : record.data.ID,
LookupName : record.data.Name + ' (from localStorage)',
LookupDescription : record.data.Description
};
localStore.add(rec);
});
// Don't sync every time you add record, sync when you finished adding records
localStore.sync();
2) If specify idProperty in model which is using localStorage, then record will not be added into localStorage.
Model
Ext.define('Local.model.Offline', {
extend: 'Ext.data.Model',
config: {
// idProperty removed
fields: [
{ name: "ID", type: "integer" }, //need an id field else model.phantom won't work correctly
{ name: "LookupName", type: "string" },
{ name: "LookupDescription", type: "string" }
],
identifier:'uuid', // IMPORTANT, needed to avoid console warnings!
proxy: {
type: 'localstorage',
id : 'news'
}
}
});

Resources