You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by "Michael C." <mc...@amica.com> on 2007/02/16 17:10:22 UTC

Re: [was: Stripping down Cocoon] AW: JSON

I am using Ajax to post a request to a servlet which formats the response as
a JSON string resembling: 

{ 
"prop1":"prop1Value", 
"prop2":"prop2Value", 
"prop3":"prop3Value" 
} 

I use this client code to convert it to a JSON object: 

var func = new Function("return "+data); 
var jsonObj = func(); 

jsonObj.prop1 ... 

Can you direct me as how to dynamically cycle through a properties object
and retrieve the elements and values when i do not know what the properties
will be since i am building this dynamically from a result set on the
server? 

I will be pulling these values and wrapping them in DOM objects for display
on a web page.  I've used arrays, but i would prefer to have a standard
return string and we would like to use the JSON properties object. 

Thanks in advance, 
Mike 


Christofer.Dutz@univativ.de wrote:
> 
> Hi Maurizio,
> 
> How about simply using an XSLT? This is the way the suggestion-list does
> it. 
> There is a file
> cocoon-forms-block.jar#org\apache\cocoon\forms\resourses\selection-list2json.xsl
> in the forms block. Just have a look at that. 
> 
> Regards,
>      Chris
> 
> [ c h r i s t o f e r   d u t z ]
> 
> IT-Berater
> univativ GmbH & Co. KG
> Robert-Bosch-Str. 7, 64293 Darmstadt
> 
> fon: 0 61 51 / 66 717 - 21
> fax: 0 61 51 / 66 717 - 29
> email: christofer.dutz@univativ.de
> http://www.univativ.de
> 
> Darmstadt, Stuttgart, Karlsruhe, Düsseldorf
> 
> -----Ursprüngliche Nachricht-----
> Von: Maurizio P. [mailto:ilmaurizio@gmail.com] 
> Gesendet: Montag, 16. Oktober 2006 00:01
> An: users@cocoon.apache.org
> Betreff: JSON
> 
> Greetings to all.
> 
> I would like to do a 'simple' JSON communication between browser and
> server  flowscript (without using all these nice dojo's widgets). I mean,
> is it possible for example to make a simple Array in flowscript and
> send it in JSON to javascript running into browser, that asked it? I can
> do it in PHP and i know it must be possible also in Cocoon (dojo does
> much more!!), but still dunno how to do it.
> 
> Is there an easy way or am i obliged to look for the ajax-block's java
> files, try to understand what the hell it does, cutting down all
> unwanted stuff, recompile and deploy as new generator?
> 
> Let u know i am not an expert of Cocoon.
> 
> Thanx 2 all who will help
> 
> 
> -- 
> Regards,
>                     Maurizio
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/JSON-tf2447215.html#a9007253
Sent from the Cocoon - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: [was: Stripping down Cocoon] AW: JSON

Posted by Jason Johnston <co...@lojjic.net>.
On Fri, 16 Feb 2007 08:10:22 -0800 (PST), "Michael C." <mc...@amica.com> wrote:
> 
> I am using Ajax to post a request to a servlet which formats the response
> as
> a JSON string resembling: 
> 
> { 
> "prop1":"prop1Value", 
> "prop2":"prop2Value", 
> "prop3":"prop3Value" 
> } 
> 
> I use this client code to convert it to a JSON object: 
> 
> var func = new Function("return "+data); 
> var jsonObj = func(); 
> 
> jsonObj.prop1 ... 
> 
> Can you direct me as how to dynamically cycle through a properties object
> and retrieve the elements and values when i do not know what the
> properties
> will be since i am building this dynamically from a result set on the
> server? 

This isn't a Cocoon-specific question, but I can answer...

Use the JavaScript for...in loop:

for(var prop in jsonObj) {
   var propValue = jsonObj[prop];
   ...
}


> 
> I will be pulling these values and wrapping them in DOM objects for
> display
> on a web page.  I've used arrays, but i would prefer to have a standard
> return string and we would like to use the JSON properties object. 
> 
> Thanks in advance, 
> Mike 
> 
> 
> Christofer.Dutz@univativ.de wrote:
>> 
>> Hi Maurizio,
>> 
>> How about simply using an XSLT? This is the way the suggestion-list does
>> it. 
>> There is a file
>>
> cocoon-forms-block.jar#org\apache\cocoon\forms\resourses\selection-list2json.xsl
>> in the forms block. Just have a look at that. 
>> 
>> Regards,
>>      Chris
>> 
>> [ c h r i s t o f e r   d u t z ]
>> 
>> IT-Berater
>> univativ GmbH & Co. KG
>> Robert-Bosch-Str. 7, 64293 Darmstadt
>> 
>> fon: 0 61 51 / 66 717 - 21
>> fax: 0 61 51 / 66 717 - 29
>> email: christofer.dutz@univativ.de
>> http://www.univativ.de
>> 
>> Darmstadt, Stuttgart, Karlsruhe, Düsseldorf
>> 
>> -----Ursprüngliche Nachricht-----
>> Von: Maurizio P. [mailto:ilmaurizio@gmail.com] 
>> Gesendet: Montag, 16. Oktober 2006 00:01
>> An: users@cocoon.apache.org
>> Betreff: JSON
>> 
>> Greetings to all.
>> 
>> I would like to do a 'simple' JSON communication between browser and
>> server  flowscript (without using all these nice dojo's widgets). I
> mean,
>> is it possible for example to make a simple Array in flowscript and
>> send it in JSON to javascript running into browser, that asked it? I can
>> do it in PHP and i know it must be possible also in Cocoon (dojo does
>> much more!!), but still dunno how to do it.
>> 
>> Is there an easy way or am i obliged to look for the ajax-block's java
>> files, try to understand what the hell it does, cutting down all
>> unwanted stuff, recompile and deploy as new generator?
>> 
>> Let u know i am not an expert of Cocoon.
>> 
>> Thanx 2 all who will help
>> 
>> 
>> -- 
>> Regards,
>>                     Maurizio
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>> For additional commands, e-mail: users-help@cocoon.apache.org
>> 
>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>> For additional commands, e-mail: users-help@cocoon.apache.org
>> 
>> 
>> 
> 
> -- 
> View this message in context:
> http://www.nabble.com/JSON-tf2447215.html#a9007253
> Sent from the Cocoon - Users mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org