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.cranf...@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=jsonparam name=rootcustomersList/param/result /action /package And finally in the Struts action I have: public MapString,Object getCustomersList() { // Get the customer data from the service layer ListCustomer 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 LinkedHashMapString,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. MapString,Object json = new LinkedHashMapString,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-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@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
RE: Ajax Response - Array Objects
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.mo...@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.cranf...@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=jsonparam name=rootcustomersList/param/result /action /package And finally in the Struts action I have: public MapString,Object getCustomersList() { // Get the customer data from the service layer ListCustomer 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 LinkedHashMapString,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. MapString,Object json = new LinkedHashMapString,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-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@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-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
RE: Ajax Response - Array Objects
!-- this is what is ..supposed.. to happen --function test() { !-- get the XmlHttpObject and assign to _c0 -- var _c0=this.getXmlhttpObject(); function isDocumentOk(_c1) { !-- get the status -- var _c2=_c1[status]; return Boolean((!_c2)||((200=_c2)(300_c2))||(_c2==304)); !-- 101 is a switch protocol error ..300's are redirect errors these are very bad errors to get from the server -- !-- turn in firebug in FF to see the status code -- } if(_be) { var _c3=this,_c4=null,gbl=dojo.global(); var xhr=dojo.evalObjPath(dojo.io.XMLHTTPTransport); !-- xhr is the Dojo JS object which is the Ajax control -- _c0.onreadystatechange=function() { !-- the xhr object is in ready state so populate your div tag here with the result returned from Action.Bean -- div.innerHtml=%{Action.Bean} } }; pull apart the JS code from the tag to determine the delta Martin Gainty __ Jogi és Bizalmassági kinyilatkoztatás/Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité Ez az üzenet bizalmas. Ha nem ön az akinek szánva volt, akkor kérjük, hogy jelentse azt nekünk vissza. Semmiféle továbbítása vagy másolatának készítése nem megengedett. Ez az üzenet csak ismeret cserét szolgál és semmiféle jogi alkalmazhatósága sincs. Mivel az electronikus üzenetek könnyen megváltoztathatóak, ezért minket semmi felelöség nem terhelhet ezen üzenet tartalma miatt. Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen. Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni. Subject: RE: Ajax Response - Array Objects Date: Fri, 16 Jul 2010 08:38:47 -0500 From: chris.cranf...@setech.com To: user@struts.apache.org 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.mo...@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.cranf...@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=jsonparam name=rootcustomersList/param/result /action /package And finally in the Struts action I have: public MapString,Object getCustomersList() { // Get the customer data from the service layer ListCustomer 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 LinkedHashMapString,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. MapString,Object json = new LinkedHashMapString,Object(); for(Customer customer : customers) { json.put(customer.getId().toString(), customer); } // Hand result
RE: Ajax Response - Array Objects (working examples)
//working dojo XmlhttpObject with messageReceived function plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/io/xip_server.html //client that calls the server via send function plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/io/xip_client.html Martin Gainty __ Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen. Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni. From: mgai...@hotmail.com To: user@struts.apache.org Subject: RE: Ajax Response - Array Objects Date: Fri, 16 Jul 2010 11:51:03 -0400 !-- this is what is ..supposed.. to happen --function test() { !-- get the XmlHttpObject and assign to _c0 -- var _c0=this.getXmlhttpObject(); function isDocumentOk(_c1) { !-- get the status -- var _c2=_c1[status]; return Boolean((!_c2)||((200=_c2)(300_c2))||(_c2==304)); !-- 101 is a switch protocol error ..300's are redirect errors these are very bad errors to get from the server -- !-- turn in firebug in FF to see the status code -- } if(_be) { var _c3=this,_c4=null,gbl=dojo.global(); var xhr=dojo.evalObjPath(dojo.io.XMLHTTPTransport); !-- xhr is the Dojo JS object which is the Ajax control -- _c0.onreadystatechange=function() { !-- the xhr object is in ready state so populate your div tag here with the result returned from Action.Bean -- div.innerHtml=%{Action.Bean} } };pull apart the JS code from the tag to determine the delta Martin Gainty __ Jogi és Bizalmassági kinyilatkoztatás/Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité Ez az üzenet bizalmas. Ha nem ön az akinek szánva volt, akkor kérjük, hogy jelentse azt nekünk vissza. Semmiféle továbbítása vagy másolatának készítése nem megengedett. Ez az üzenet csak ismeret cserét szolgál és semmiféle jogi alkalmazhatósága sincs. Mivel az electronikus üzenetek könnyen megváltoztathatóak, ezért minket semmi felelöség nem terhelhet ezen üzenet tartalma miatt. Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen. Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni. Subject: RE: Ajax Response - Array Objects Date: Fri, 16 Jul 2010 08:38:47 -0500 From: chris.cranf...@setech.com To: user@struts.apache.org 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.mo...@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.cranf...@setech.com To: user@struts.apache.org Date: 15-07-2010 19:04 Subject: Ajax Response - Array
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=jsonparam name=rootcustomersList/param/result /action /package And finally in the Struts action I have: public MapString,Object getCustomersList() { // Get the customer data from the service layer ListCustomer 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 LinkedHashMapString,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. MapString,Object json = new LinkedHashMapString,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-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org