• Post Reply Bookmark Topic Watch Topic
  • New Topic

formatting JSON for jqGrid  RSS feed

 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, so I thought I would try to implement jqGrid. It looked really sweet and click. But support for it has vanished. I send an email to the author with no response, and the only documentation are his examples that highlight its features. It doesn't explain what is "needed" or can be excluded. Its very poor. So I'm trying to implement this with servlets but I don't think his implementation will let me.

Has anyone worked with jqGrid by returning JSON from a servlet? If not, does anyone know of a good plugin that will take a JSON string and create a table?

Or am I all alone on this and need to try to write something myself?
[ January 22, 2008: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whether a response is generated by a servlet, HTML, php, or Fred's Fabulous Fuddwinkle is all the same to the client. Perhaps you should post what issues you are having rather than venting.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've implemented jqGrid successfully returning JSON from the server. As Bear said, what issues are you having? Maybe I can help.
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't really know what the true issue is. But here is what happens...I return JSON from my servlet. Firebug confirms that it comes across just fine. How jqGrid parses through the JSON I have no idea. I'm looking at his code right now to try and figure it out. It creates the table header and the table body, but none of my data makes it in there. His examples are in PHP (which I've never worked with) so figuring out exactly what he is returning and how he is returning it in his examples is kind of difficult.

I'm now under the impression that I HAVE to return a value for 'page' and 'total'. He uses these for paging. But it seems that not returning these in the JSON messes something up. How do I debug javascript using Firebug so that I can step through his code and see where he is going and what he is looking for and see what I'm giving him for values?

Thanks Bryce
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you provide your json string I Can probably help you. Just ease up a bit. ;) Here is my json. This is a return of 2 records.

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the JSON that is required is not documented -- and we all know how bad the average devo is at documentation -- perhaps you could set up php on your system (it's fairly straight-forward) and run his demo using FireBug to see what JSON is being generated. Then it's a matter of reverse engineering.
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did figure out debugging with Firebug. I got in contact with Tony. So I'll be corresponding with him on this. If you have anything though it would be greatly appreciated...

here is the JSON that I'm returning from the servlet...



Am I missing anything here?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or you could just look at Gregg's! (who snuck his post in before mine)
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A list of beans is not the way to go here. StringTree isn't going to be able to help me I don't think. I think I'm going to have to write my own JSON back as plain text. Its a little more work, but not too much once I get it set up. I have loadonce:true, so I don't need to return pager. But I still need to return total, and rows. Thanks for the look at what the JSON structure should look like. That helps a TON.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually using a JSON lib of some sort (whether its StringTree or not) would be the best way to go. Sometimes I myself get hung up on what Model objects I should and should not create. But if you look at what JavaBeans are used for it makes perfect sense. This isn't verbatim but will give you an idea:



And then the JSON lib should turn that into the string you need.
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what I'm doing is looping through my resultset and each row of the resultset is one bean. Then I add the bean to an ArrayList. The arraylist is what is being JSONized the results of which I posted. Is there another (better) way?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bryce Martin:
what I'm doing is looping through my resultset and each row of the resultset is one bean. Then I add the bean to an ArrayList. The arraylist is what is being JSONized the results of which I posted. Is there another (better) way?


Did you read my post? Just put your beans in the object I showed in the rows list. Then "jsonisize" the entire object.
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So this is how I have the transport class set up...



it wouldn't let me put the 'rows' after the GetResults like you had it written. I think this will just create a list called GetResults. How do I get it to pull in that GetResults bean? I've never created a Serializable class before, so I'm real uncertain about what's going on here...

Sorry to be such a pain on something that is probably pretty basic Java...
[ January 22, 2008: Message edited by: Bryce Martin ]
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I might have figured out how this Serializable bit is working...

Here is my Transport class...


Then I need to create an instance of this class in my SearchResults code...

JQGridJSONTransport myJSON = new JQGridJSONTransport();

and then I have this piece of code...


ECHCEHSILRCM is the name of my result set. And then I finally do this...



I'm posting this for you to see so that if something glaringly obvious jumps out at you then you can point it out to me. I'm going to try testing it out now.
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do I have to make my GetResults bean Serializable as well??
Do I need a contructor?

The List is not being populated with anything. When I JSONize it firebug tells me that the list: null.
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm still getting that "class" bit out front. I don't think StringTree JSON is the way to go here. Either that or I need to set something up differently when using it...

This is my latest results returned...



It still doesn't quite look right. I'm guessing that "rows" will be broken out when I finally get something in it?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bryce Martin:
Do I have to make my GetResults bean Serializable as well??
Do I need a contructor?

The List is not being populated with anything. When I JSONize it firebug tells me that the list: null.


What does the server side code tell you? To be honest I am a bit concerned that you are doing this type of development but have never ran across the Serializable interface.

All that does is tell something "hey, you can write me to disk if you want". In general when you are dealing with web applications you'll want objects that are passed around in session to be Serializable since most session mechanisms write session data to disk.

With that being said, this discussion is not really about HTML/JavaScript anymore. Lets do this. I am going to move this to Java in General (Intermediate) and lets get the java part working. Once that is done we can start a new topic if you still can't get the JavaScript part working...
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yea, StringTree may be doing a bit more than what you need and I am not familiar enough with it to say how to make it not do what it is doing. If that makes sense.
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, that makes perfect sense. I haven't used it enough yet to know either. What lib are you using to JSONize your objects?

As far as writing Serializable objects to disk that I want saved in the session... I set a bean to be seen by the session using HttpSession session = request.getSession(true);

Then I just put that in any servlet that needs to access the session variables. It has worked fine, but then again I may have just gotten lucky. I haven't explicitly defined anything as Serializable before and haven't had any problems....what kinds of things would I be running into?
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not saving session data on the server side. I'm just doing it in the browser. that is why I never had to Serialize my objects. If I'm not going to save session data to the server should I worry about it?
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I worked through the kinks of creating that Transport class. Here is my new JSON string that is returned...

 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bada bing bada boom. I got it working. Now its time to play. Hopefully Tony will send me the style sheet so I can play with that too
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pete, please see check your private messages regarding an urgent matter.

Thanks.
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Pete NoSpam" please check your private messages for an important administrative message.

And why have you resurrected an old thread from January rather than starting anew? Please read this FAQ.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!