Thursday, June 25, 2009

Tiffany Granath Panties

use of Gmail, Calendar, Docs and Apps at universities in Germany and worldwide

The Google Web Toolkit GWT

offers native already has a relatively easy way usable

be made to simplify the implementation of the JSON data in GWT using static files available. In my Google about the plugin have created the Eclipse project

/ was
    folder that contains GWT version 1.6 are a complete Web application. For the static JSON files there just created a subdirectory, let's call him
  • model / .
  • example file:
was / / model / abschluss.json

[

{id: 123, name: degree 1, (c) H. Brune symbol: Abs1 }, { id: 456, name: degree 2,

symbol: Abs2

},

]

This file may Jetty Server that is started in Ecplise, are available on http://localhost:8080/modell/abschluss.json

(or under the configured port).

 






JSON with GWT








This works only a very brief sketch like this, the detailed description can be found in this
GWT 1.6 Page
:

Creating









JSON source (we have)







stub class , Which implements create JSNI methods to directly access the contents of the JSON structure. Instances of the stub class generated by a JSNI method that essentially

eval ()
calls (note the safety instructions!)








    implementation of an asynchronous
    request builder
    call, the JSON data collected and processed .







  1. generating a representation, z. As a Grid .









  2. Important: Do not
    The URL to the JSON file
    GWT.getModuleBaseURL ()
    be preceded by as shown in the GWT tutorial. It extends an indication of this type:





  3. private static final String JSON_URL
  4. = "/ model / abschluss.json";








experience









 The implementation of the stub class can mean annoying repetition of work, if appropriate on the server side already are (bean) classes. Here, however, can not achieve Reuse 







Once you have the stub classes, the rest of the implementation relatively easy, apart from the usual 'hardship' of the representation with the relatively primitive GWT widgets










    Source







  • package com.chb.gxt2m3.client;
  • com.google.gwt.core.client.EntryPoint import;
    com.google import. gwt.core.client.JsArray;
    import com.google.gwt.event.dom.client.ClickEvent;
  • import com.google.gwt.event.dom.client.ClickHandler;
    import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestBuilder;
com.google import. gwt.http.client.RequestCallback;
import com.google.gwt.http.client.RequestException;
import com.google.gwt.http.client.Response;
import com.google.gwt.user.client.ui. Button;
com.google.gwt.user.client.ui.Grid import, import
com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
public class GXTTest implements EntryPoint {public void

onModuleLoad () {

btLaden Button = new Button ("Load");
RootPanel.get ("buttons") add (btLaden).

btLaden.addClickHandler (new click handler () {public void onClick
 (click event) {
refreshAbschluesse ();}


});
} private static final String

JSON_URL_ABS = "/ model / abschluesse.json";

private void refreshAbschluesse () {

RootPanel.get ("display") clear ();.
RootPanel.get (" display "). add (
new Label (" financial statements are loaded of "+ JSON_URL_ABS));

request builder builder builder = new request (RequestBuilder.GET,
JSON_URL_ABS);

try {
builder.sendRequest (null, new request callback () {public void onError

(Request request, Throwable exception) {
display error ("JSON call could not be executed");}


public void onResponseReceived (Request request, Response response
) {

if (200 == response.getStatusCode ()) {

ClearError ();
abschluesseZeigen (asArrayOfAbsData (response.getText ()));} else {


display error ("Failed to call JSON (
response.getStatusText + () + ")");}


}
});} catch
(request Exception e) {
display error ("access to JSON failed");}



} private void abschluesseZeigen (JsArray
abs) {

RootPanel.get ("display") . clear ();

if (abs == null
Name "));

for (int idx = 0; idx \u0026lt;abs.length (), idx + +) {a = data
statements abs.get (idx);
agrid.setWidget (idx + 1, 0, new Label ("" +
a.getId ()));
agrid.setWidget (idx + 1, 1, new Label (a.getKuerzel ()));
agrid.setWidget (idx + 1, 2, new Label ("" + a.getName
()));}}



} private void clear error () {
RootPanel.get ("errorMsg") clear ();.
}

private void display error (String error) {
clear error ();
if (error = null)
RootPanel.get ("errorMsg") add (new Label (error));.
}
private final native JsArray
asArrayOfAbsData (String json) / *- {return
eval (json);}
}-*/;






JSON with GXT







A strength GXT (whose version 2 is available today as Milestone 3) are certainly the great widgets and Databinding ways through which changes the underlying data model to sign in all parts of the application can be. Unfortunately in the demo page only
Grid example with an XML source
. Anything but a search shows that there is a
JsonReader
. One can transfer the sample also.









One problem is the structure of the JSON file. Apparently, nested styles are not possible, at least you can understand this thread in the ExtJS Forum
be so.








There are, however, a different example:
http://extjs.net/forum/showthread.php?t=71978



0 comments:

Post a Comment