1

Does Dojo support JSON Object to dijit/form/Form mapping? I'm well aware of this but I couldn't find any detailed example of how to do this.

William Wino
  • 3,599
  • 7
  • 38
  • 61

3 Answers3

2

so if I understand well enough (the question is not really that detailed), you want to use an object and all the properties of that object should map to fields in your form? Well, that's possible using the getValues() and setValues() function.

For example:

var myObject = {
    test1: "test5",
    test2: "test6",
    test3: "test7",
    test4: "test8"
};
registry.byId("form").setValues(myObject);

Retrieving the same kind of object can be done with the appropriate getter, for example:

registry.byId("form").getValues();

I also made an example using JSFiddle.

g00glen00b
  • 41,995
  • 13
  • 95
  • 133
  • Hi thanks for your answer. It helps a lot! One more thing, can the registry also handle nested objects? If so how? – William Wino Dec 17 '13 at 08:13
  • Can you explain that a bit more? I think you're misinterpreting the functionality of the `registry`. The registry retrieves widgets, so the `getValues` or `setValues` function is not in the `registry` API, but it is a part of the `dijit/form/Form` API (it's the object you retrieve from the registry). – g00glen00b Dec 17 '13 at 08:19
  • That being said... the object that is used maps the property name on the form widget with the same `name` attribute. So I don't think nesting is allowed (if that's your question). – g00glen00b Dec 17 '13 at 08:20
  • Interestingly enough, I found out that it supports nested object. Here take a look at the JSFiddle I had updated : [JSFiddle](http://jsfiddle.net/fAq5z/1/). – William Wino Dec 17 '13 at 08:29
  • Thanks dude, you helped me a lot! Geez, how come I didn't notice such functions in the form class. – William Wino Dec 17 '13 at 08:30
  • No problem, the best tool to see which functions there are is the API documentation (http://dojotoolkit.org/api/dijit/form/Form.html). Too bad it isn't described what the function exactly does (that's why I wasn't sure about the nested objects), but in combination with a simple sandbox like JSFiddle that's easily tested. – g00glen00b Dec 17 '13 at 08:40
  • I love Dojo! But to be honest I kinda hate that it lacks detailed and easy-to-follow examples/documentation. And it's really hard to find some info about Dojo on Google despite that it's been around for quite awhile. The official community feels so neglected, it feels like there aren't many Dojo users out there. How come a good library like this isn't popular? – William Wino Dec 17 '13 at 08:54
  • 2
    I have the same feeling. The problem is that there is no marketing team (I think), so the only possible way to become popular is to have a wide user base that spreads the word. To have a big user base you need an attractive documentation, which Dojo clearly lacks. I often hear that Dojo is properly documented, but this question just prooves it isn't. So the only people who use Dojo are people who dig deeper into it by thereself (without documentation), but that means there is no big community behind it and so the word isn't spreaded that fast. – g00glen00b Dec 17 '13 at 09:01
  • for dojo >=1.10 you need to use `set('value')` and `get('value', values)` – Castro Roy Apr 08 '15 at 20:55
0

DOJO plugin is deprecated in struts 2.1.x - http://struts.apache.org/release/2.1.x/docs/ajax-tags.html

Better use annotations for JSON to form binding , check this - How to bind JSON to Java object in Struts2 using struts2-json-plugin

Community
  • 1
  • 1
Sadanand
  • 1,080
  • 3
  • 13
  • 30
0

Dojo has an MVC package, used for binding elemnts to JSON values. The dojo/mvc/at does the widget to json binding

http://dojotoolkit.org/reference-guide/1.9/dojox/mvc.html

tik27
  • 2,698
  • 1
  • 16
  • 25
  • Well..I just don't understand how to relate that to my case. Maybe I'm too stupid for that. I simply just want to set a `JSON Object` to a `From`. Can you walk me through it? – William Wino Dec 17 '13 at 07:20
  • If that is all you want, then this is overkill. This is for 2 way syncing of and JSON object to all widget values. it like knockout.js – tik27 Dec 17 '13 at 15:14