I cannot seem to get my Ajax request to return to the Ajax client an
array of objects. Instead of simply returning a key/value pair, I've
read that it is possible to return the actual domain objects, but I have
been unsuccessful. Each time, my combo box is populated with three
values, "message type number".
In the JSP I have:
<sx:autocompleter
href="%{customersUrl}"
preload="true"
name="customer"
valueNotifyTopics="/CustomerChanged"
forceValidOption="true"
/>
In the Struts configuration I have:
<package name="ajaxpkg" namespace="/ajax" extends="json-default">
<action name="ajaxCustomersList"
class="com.examples.struts2.action.JsonAction">
<result type="json"><param
name="root">customersList</param></result>
</action>
</package>
And finally in the Struts action I have:
public Map<String,Object> getCustomersList()
{
// Get the customer data from the service layer
List<Customer> customers = customerService.getAllCustomers();
// If no data was returned, return an empty collection
// as the browser will display an empty list.
if(customers == null)
return new LinkedHashMap<String,Object>();
// Data was obviously returned, create new map and populate
// the map with the customer ID as the key and the actual
// customer object as the payload for each pair.
Map<String,Object> json = new LinkedHashMap<String,Object>();
for(Customer customer : customers) {
json.put(customer.getId().toString(), customer);
}
// Hand result back to Ajax client
return(json);
}
Can anyone explain what I have missed here in my implementation and/or
what needs to be corrected.
Thanks,
Chris
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]