View Full Version : Problem JsonStore and '\n'

9 Feb 2010, 7:55 AM
Hi everybody... i don't know if this is a bug or I'm justing messing everything :P, but here what it's happening....

I have a Jstore that does an SQL query and gets the table with ID and a comment (it's a big text, but to do the label I just get the 15 first =P)...

The problem is that if there is an '\n' in the text the JsonStore never finishes the loading! =P (to test this I did the alert down)

Is it a bug or I'm doing all wrong???

here is the code

var referenceForm = this;
var request = "select distinct FM_REFERENCE.ID_COMMENT as id, SUBSTR(COMMENT_TEXT, 0, 15)||' ...' as label from FM_COMMENT, FM_REFERENCE where FM_COMMENT.ID_COMMENT = FM_REFERENCE.ID_COMMENT order by label asc";

var JStore = new Ext.data.JsonStore({
autoLoad: true,
url: 'GetDatabaseListByRequest.action?request=' + request,
root: 'results',
fields: ['id', 'label'],
listeners: {
load: function() {
var r = new Ext.data.Record({
'id': '0',
'label': 'New...'
this.insert(0, r);

JStore.on('load', function(){

Thanks for the answers!

10 Feb 2010, 12:13 AM

10 Feb 2010, 12:49 AM
Please tell me that you have not coded GetDatabaseListByRequest.action to execute whatever SQL statement it receives in the "request" parameter!

And use a JSON library to encode your returned data.

Mike Robinson
10 Feb 2010, 8:13 AM
Glancing at your code, I'd suggest that I suspect I'm looking at "code that works ... somehow." (As in: "whack! whack! whack! there!! it's stopped wigglin' ...")

(And please take that in the light-hearted spirit intended.) ~o)

There's probably a better way to write this code. A way that is closer to what you see in the examples. For instance, you won't find a phrase like ?request=' + request in any of my code nor in any of the code I've yet seen.

You also won't see a JsonStore object, whose expressed purpose is to load data into itself, having within a load-event handler ... code to load data into itself!

Ext.data.JsonStore is not Ext.Ajax.Request. I see a lot of painful bruises in this code, and I suspect that while you may have stumbled to "something that works, so to speak," you are a long way away from "the designer's intent." You're building a scaffolding next to a working elevator and laboriously climbing to the second floor without a rope. Step back and take a very long second-look at what you've got here.

JM2CW. HTH. No offense intended. Peace.

11 Feb 2010, 12:28 AM
Hi everybody!

Thanks for the answers =P (I have a light-hearted spirit :D)

Well... this code isn't mine... I started last week (at 01/02) at my internship and I'm not familiarized with javascript or Extjs.... in fact my bosses just gave me some part of the code and said "This is the code, and this is the error... Good Luck!" =P... So the "?request" part was already there =P

So... if I understood well, I should do the SQL query with Ext.Ajax.Request isn't it? And I should get the answer in the sucess: part and treat it not? There is a easy way to store the answer, like.... to transform it in a Store object easily?

One more time... Thanks for everybody! You are helping a lot! =D

11 Feb 2010, 2:40 AM
OK, you inherited that stuff, it's understandable that you need help.

But for a start, ask your bosses what would happen if someone did

url: 'GetDatabaseListByRequest.action?request=drop FM_COMMENT;'

But as to your question. of course if there's a line break in the data, and this is returned unconverted, then the JSON won't be correct. It's broken in two with a line break.

JSON packets MUST be constructed with a JSON library.