ofbiz-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sascha Rodekamp <sascha.rodekamp.lynx...@googlemail.com>
Subject Re: AJAX JSON response
Date Thu, 01 Jul 2010 14:36:44 GMT
I use the normal java event handler when working with json objects. You can
pass the JSON String/ Array as normal parameter to your Event. In the Event/
Service you can simply parse the parameter String into a JSON Object:
    JSONObject jsonObject = JSONObject.fromObject(jsonStringFromParameter);

Do some stuff with the jsonObject change/edit/add Data and transform back to
a String.

This String can be written into your response Object.
    1) Set the Content Type to "application/x-json"
    2) set the Content length
    3) Get the response writer and write the json String to your response

If your calling the Event/ Service with an Ajax Request you can user the
evalJSON() Method.
new Ajax.Request("/youreRequestHere", {
                        method: "get",
                        parameters: {"parameter": "data23"},
                        onSuccess: function(transport){
                            var jsonData =
                            //here you can update you're div with the data


The controller entry looks like this

    <request-map uri="youreRequestHere">
        <security auth="false" https="false" />
        <event type="java" invoke="yourEventHere" path="x.y.z"/>
        <response name="success" type="none" />
        <response name="error" type="none" />

BTW: why you're working with JSON Data when you want simply update a div?
Creat a normal Screen and a normal controller entry which calls the screen.
Then Do you're Ajax Request, the response will be the difined Screen which
you can insert / replace in your're div you wan't to update.


2010/7/1 Levenimeux <yassine.elkachchani@gmail.com>

> thanks sasha for your answer
>  but can you explain me more how to parse my arguments to the event/service
> (i guess you mean minilang or java classes to invoke). by the way after
> posting my question i was trying to use the JSONJavaHandler when firing
> request to my uri....but now after reading your answer  i get a quetion
> about this ....do i have to use necessarly the DojoJSONserviceHandler or
> can
> i use the JSONJavaHandler instead and if this is the case do i have to do
> some modifications ???  i suppose that if i use the DojoJSONserviceHandler
> like you propose i have to write a service (in minilang or even java). if
> we
> consider those conditions are verified  how do i have to write my urimap in
> the controller i mean
> ---------------------------
>  < request-map type="java or service according to the service ive wrote"
> path="my service or java class path"  invoke="the method to invoke if
> event">
> <response name="succes" type="request" value="in the biginning ive used
> json
> but i had the kind of result ive described before and after  i used /view
>  >
> --------------------------
> but i guess i don't get it the best way because it not work as it must (
> now
> the downloadable file ive described before don't popup anymore)
>  now can you explain me the right request-map i have to write (when using
> the DojoJSONserviceHandler or even just the JSONjavaHandler and how to use
> them)
> if it possible can you send me just an example (project or url) using the
> way youre describing and the related configurations...
> thank alot for advance .....
> --
> View this message in context:
> http://ofbiz.135035.n4.nabble.com/AJAX-JSON-response-tp2274772p2275011.html
> Sent from the OFBiz - User mailing list archive at Nabble.com.

Sascha Rodekamp
   Lynx-Consulting GmbH
   Johanniskirchplatz 6
   D-33615 Bielefeld

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