问题
I am new to Spring mvc3 portlet and dojo. I am trying to populate select dropdown with JSON data when jsp is loaded. I want to use dojo and give ajax call to controller and return JSON when jsp is loaded. Any tips will be helpful.
回答1:
@Controller
@RequestMapping("/yourController")
public class YourController
{
@RequestMapping(value="/combo/{id}", method=ReqestNethod.GET)
public String getDropDownData(@ParamValue("id") long id)
{
List<Combo> combos = commonDao.getCombos(id);
String json = JsonUtil.toJson(combos); // or whichever way you use
return json;
}
}
Send requests from dojo to this url
<your-context-path>/yourController/combo/1
where 1 is your combo id.
I haven't checked the syntax here.. Wrote it blind. You might get compilation errors.
回答2:
I get data in below format How do I populate dojoType="xwt.widget.form.FilteringSelect" {"ValuesDTO": {"items": [{},{"default": {"size": 5},"int": 10,"string": "Product1","string": "Product1 ","string": "product3","string": "product4","string": "product5"}]}}
I am sending dat in bean--->DTO--->List
来源:https://stackoverflow.com/questions/10781112/spring3mvcportlet-populate-json-dojo-select