Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    How to instantiate DynamicForm(JsonObject)

    There is a typo in the title of this question. It should be
    How to instantiate DynamicForm(JavascriptObject).
    ----

    I would like to know how to instantiate DynamicForm(JavascriptObject).

    I have a static file address.json:
    Code:
    var addressjson = {
    	dataPath : "address",
    	items : [ {
    		"type" : "text",
    		"name" : "street"
    	}, {
    		"type" : "text",
    		"name" : "unit"
    	}, {
    		"type" : "text",
    		"name" : "city"
    	}, {
    		"type" : "text",
    		"name" : "province"
    	}, {
    		"type" : "text",
    		"name" : "country"
    	}, {
    		"type" : "text",
    		"name" : "zip"
    	} ]
    }
    eatJson(addressjson);
    My code ate that and produced a JavascriptObject jso. To verify that the json was eaten correctly, I did
    Code:
    JSONObject json = new JSONObject(jso);
    which verified it to be
    Code:
    {
      "dataPath":"address",
      "items":[
       {"type":"text", "name":"street"},
       {"type":"text", "name":"unit"},
       {"type":"text", "name":"city"},
       {"type":"text", "name":"province"},
       {"type":"text", "name":"country"},
       {"type":"text", "name":"zip"}
     ]
    }
    Which means jso is indeed a proper JavascriptObject.
    Then jso was fed as an argument
    Code:
    form = new DynamicForm(jso);
    and on attachment to a Canvas, an exception was thrown, which says something similar to
    "the object returned from JSNI is not a valid js object".

    My questions are
    1. Is this the right json structure as an argument for the constructor
    Code:
    DynamicForm(JavascriptObject)
    ?
    If not, what is the right structure of the json, which when produced as a JavascriptObject, could be used as the constructor's argument.

    2. Is this constructor even meant to be used for constructing the fields of a DynamicForm? If not what is it used for and what should the structure of the JavascriptObject be?
    Last edited by BlessedGeek; 20 Jul 2010, 15:37.

    #2
    What it is expecting is the actual javascript instantiated object, just like you would declare in SmartClient. Easiest way is look at the SmartClient examples, add a DynamicForm directly into your 'script' in your host file, then load that object i.e. isc.DynamicForm.create(...). In fact all SmartGWT widgets have a protected create() method which does this in JSNI really.

    Comment

    Working...
    X