[T5] JSONObject response

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[T5] JSONObject response

Adriaan Joubert-3
Hi,

I'm having a problem with returning a JSON object from an actionlink
in (5.0.11-SNAPSHOT). I have some javascript that submits a request,
which works great, and the actionhandler returns a JSONObject as
follows


Object onUpdate() {
        ....
        JSONObject json = new JSONObject();
        json.put("fcId", fcId);
        return json;
}

This works fine, but on the client side I get:

onComplete : function(transport) {
         var response = transport.responseText;
// if (response.length>2 && response.endsWith("{}"))
// response = response.substring(0,response.length-2);
        var reply = response.evalJSON(true);
        ....
}

The responseText contains

{"fcId":36178}{}

If I strip of the additional two braces everything is great and the
reply is parsed correctly, but I must be doing something wrong.
prototype.js says that JSON objects are often accessible directly from
transport.headerJSON, but this is null in my case. Anybody got any
ideas what I need to do to not have the additional 2 braces?

Thanks,

Adriaan

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [T5] JSONObject response

Sven Homburg
in class "AjaxComponentEventRequestHandler" the method "handle"
creates an empty JSONObject, i cant checkout why.

is it a bug or a feature?

2008/2/27, Adriaan Joubert <[hidden email]>:

>
> Hi,
>
> I'm having a problem with returning a JSON object from an actionlink
> in (5.0.11-SNAPSHOT). I have some javascript that submits a request,
> which works great, and the actionhandler returns a JSONObject as
> follows
>
>
> Object onUpdate() {
>         ....
>         JSONObject json = new JSONObject();
>         json.put("fcId", fcId);
>         return json;
> }
>
> This works fine, but on the client side I get:
>
> onComplete : function(transport) {
>          var response = transport.responseText;
> //      if (response.length>2 && response.endsWith("{}"))
> //              response = response.substring(0,response.length-2);
>         var reply = response.evalJSON(true);
>         ....
> }
>
> The responseText contains
>
> {"fcId":36178}{}
>
> If I strip of the additional two braces everything is great and the
> reply is parsed correctly, but I must be doing something wrong.
> prototype.js says that JSON objects are often accessible directly from
> transport.headerJSON, but this is null in my case. Anybody got any
> ideas what I need to do to not have the additional 2 braces?
>
> Thanks,
>
> Adriaan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
with regards
Sven Homburg
Reply | Threaded
Open this post in threaded view
|

Re: [T5] JSONObject response

Howard Lewis Ship
Looks like a bug, its supposed to be for the case where the event
handler returns null, but it seems like it's getting added in even for
event handlers that return a JSONObject.

On Thu, Feb 28, 2008 at 1:03 PM, Sven Homburg <[hidden email]> wrote:

> in class "AjaxComponentEventRequestHandler" the method "handle"
>  creates an empty JSONObject, i cant checkout why.
>
>  is it a bug or a feature?
>
>  2008/2/27, Adriaan Joubert <[hidden email]>:
>
>
> >
>  > Hi,
>  >
>  > I'm having a problem with returning a JSON object from an actionlink
>  > in (5.0.11-SNAPSHOT). I have some javascript that submits a request,
>  > which works great, and the actionhandler returns a JSONObject as
>  > follows
>  >
>  >
>  > Object onUpdate() {
>  >         ....
>  >         JSONObject json = new JSONObject();
>  >         json.put("fcId", fcId);
>  >         return json;
>  > }
>  >
>  > This works fine, but on the client side I get:
>  >
>  > onComplete : function(transport) {
>  >          var response = transport.responseText;
>  > //      if (response.length>2 && response.endsWith("{}"))
>  > //              response = response.substring(0,response.length-2);
>  >         var reply = response.evalJSON(true);
>  >         ....
>  > }
>  >
>  > The responseText contains
>  >
>  > {"fcId":36178}{}
>  >
>  > If I strip of the additional two braces everything is great and the
>  > reply is parsed correctly, but I must be doing something wrong.
>  > prototype.js says that JSON objects are often accessible directly from
>  > transport.headerJSON, but this is null in my case. Anybody got any
>  > ideas what I need to do to not have the additional 2 braces?
>  >
>  > Thanks,
>  >
>  > Adriaan
>  >
>  > ---------------------------------------------------------------------
>  > To unsubscribe, e-mail: [hidden email]
>  > For additional commands, e-mail: [hidden email]
>  >
>  >
>
>
>  --
>  with regards
>  Sven Homburg
>



--
Howard M. Lewis Ship

Creator Apache Tapestry and Apache HiveMind

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [T5] JSONObject response

Adriaan Joubert-3
Thanks!

I've added it in JIRA as TAPESTRY-2209

Cheers,

Adriaan

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]