I am trying to populate a combobox in ExtJS4 from the struts2 response. But the values are not populated and the combobox is empty. I also tried hard-coding the json data but still it does not work. When I try to append the actionName to the URL and execute the action, there is no error and I can see the json data..
"{'rows': [{'id': '1','name': 'Google' }, {'id': '2','name': 'Microsoft' }, {'id': '3','name': 'Yahoo' }]} "
I have a form panel, within the form panel I have a combobox item like this:
{
name: 'bName',
xtype: 'combobox',
displayField: 'name',
valueField: 'id',
store: new Ext.data.Store({
fields: [{id: 'id'}, {name: 'name'}],
autoLoad: true,
proxy: {
type: 'ajax',
url: 'getBookList',
reader: {
type: 'json',
root: 'rows'
}
}
})
}
Here is my struts.xml. I have used the json-plugin and the parameter tag is used so that the json is sent as it is,
<package name="ELM29" extends="struts-default,json-default">
<action name="getBookList" class="com.test.elm.action.Data"
method="getBookList">
<result type="json">
<param name="root">data</param>
</result>
</action>
</package>
Then I have the Book.java where I have the getter setter for the variables including data as a variable and the getBookList method where I am just assigning value to data and returning SUCCESS.
public String getBookList(){
data= "{'rows': [{'id':'1','name':'Google'},{'id':'2','name':'Microsoft'},{'id':'3','name':'Yahoo'}]} ";
return ActionSupport.SUCCESS;
}
I also tried using Ext.data.JsonStore
but it did not help. The problem is caused because of the store or the combobox? What is wrong in the code?