I am struggling to get the JSON response from my Struts2 Action class, I think i am missing something. The following set up I have in my Project.
in my module level action definition , The configuration looks like :
<package name="customer" namespace="/" extends="struts-default,json-default">
<action name="getCustomer" method="getCustomerBusiness" class="CustomerAction">
<result type="json"/>
</action>
</package>
in my Struts.xml I have
<result-types>
<result-type name="json" class="org.apache.struts2.json.JSONResult"/>
</result-types>
<interceptors>
<interceptor name="json" class="org.apache.struts2.json.JSONInterceptor"/>
</interceptors>
In My Action Class:
public class CustomerAction extends ActionSupport implements ServletRequestAware,
ServletResponseAware, ModelDriven {
private List<CustomerBean> cpbeanList;
public List<CustomerBean> getCpbeanList() {
return cpbeanList;
}
public void setCpbeanList(List<CustomerBean> cpbeanList) {
this.cpbeanList = cpbeanList;
}
public String getCustomerBusiness() {
cpbeanList = new ArrayList<CustomerPortfolioBean>();
// jsonData = new LinkedHashMap<String, Object>();
CustomerBean cb1 = new CustomerPortfolioBean();
cb1.setBusinessNm("IBM");
cb1.setBusinessAddr("475 Anton Blvd");
cb1.setBusinessPh("00000000");
cb1.setBusinessCity("Costamesa");
cb1.setBusinessStateCd("CA");
c1.setBusinessZip("92704");
similarly cb2, cb3, cb4.
cpbeanList.add(cb1);
cpbeanList.add(cb2);
cpbeanList.add(cb3);
cpbeanList.add(cb4);
return SUCCESS;
}
}
The JSON request http://localhost:8080/customer/getCustomer
returns me empty array {} In the firebug ...I am able to see.
Also I am trying the out put as data table input in JQuery. which doesn't have row because of this.
Any one's help is greatly appreciated.