struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "CRANFORD, CHRIS" <Chris.Cranf...@setech.com>
Subject RE: Ajax Response - Array Objects
Date Fri, 16 Jul 2010 13:38:47 GMT

Thanks for the suggestion, that worked.  

Now what I find odd is that when using the listKey/listValue parameters
for the autocompleter tag, it doesn't populate the dropdown when the
data is sourced from a remote URL.  If I request the Ajax service, I get
the serialized data as I would have expected, but for some reason the
widget isn't populating the dropdown with it now.  

Any suggestions? 

> -----Original Message-----
> From: Rahul Mohan [mailto:rahul.mohan@tcs.com]
> Sent: Friday, July 16, 2010 1:10 AM
> To: Struts Users Mailing List
> Subject: Re: Ajax Response - Array Objects
> 
> Chris,
> 
> Maps are serialized as 'name : value' pairs, whereas Lists are
> serialized
> as Arrays. Change your return type to a List and try.
> 
> - Rahul
> 
> 
> 
> From:
> "CRANFORD, CHRIS" <Chris.Cranford@setech.com>
> To:
> <user@struts.apache.org>
> Date:
> 15-07-2010 19:04
> Subject:
> 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:
> 
> <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: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 
> =====-----=====-----=====
> 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
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message