struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rahul Mohan <>
Subject Re: Ajax Response - Array Objects
Date Fri, 16 Jul 2010 06:10:02 GMT

Maps are serialized as 'name : value' pairs, whereas Lists are serialized 
as Arrays. Change your return type to a List and try.

- Rahul 

15-07-2010 19:04
Ajax Response - Array Objects

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:


In the Struts configuration I have:

<package name="ajaxpkg" namespace="/ajax" extends="json-default">
  <action name="ajaxCustomersList"
    <result type="json"><param

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

Can anyone explain what I have missed here in my implementation and/or
what needs to be corrected. 


To unsubscribe, e-mail:
For additional commands, e-mail:

Notice: The information contained in this e-mail
message and/or attachments to it may contain 
confidential or privileged information. If you are 
not the intended recipient, any dissemination, use, 
review, distribution, printing or copying of the 
information contained in this e-mail message 
and/or attachments to it are strictly prohibited. If 
you have received this communication in error, 
please notify us by reply e-mail or telephone and 
immediately and permanently delete the message 
and any attachments. Thank you

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message