You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "Poggenpohl, Daniel" <Da...@isst.fraunhofer.de> on 2015/10/28 11:16:21 UTC

How to send additional data with an ajax response

Hello everyone,

we have a problem where we update some page with an ajax request, but need additional data to be sent with the ajax response. This additional data should then be consumed on the client side by an ajaxComplete event. Does anyone know how a Tapestry event method can return more than just getBody() in the response? We would need to return a response containing both the new body and a JSONObject for consumption.

Regards,
Daniel P.

Re: AW: AW: How to send additional data with an ajax response

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Fri, 30 Oct 2015 07:45:18 -0200, Poggenpohl, Daniel  
<Da...@isst.fraunhofer.de> wrote:

> Hello,

Hi!

> sorry, when I wrote the question I had totally forgotten about your post.
> So you mean the HTML5 method of having, for example, a div element like  
> this: <div data-additionalData="myData"> ?

Yep! I'd just add the attributes to some existing HTML element

> If you meant that, I haven't used this method yet for anything.

That's the method Tapestry 5.4 itself uses.

> Wouldn't that bloat the sent source if the additionalData is a big  
> JSONArray? (I do not know anything about data tags yet, will inform  
> myself)

Yes, but then your response would be big anyway, data in HTML attributes  
or in a JSON object.

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

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


Re: AW: AW: How to send additional data with an ajax response

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Fri, 30 Oct 2015 07:48:11 -0200, Poggenpohl, Daniel  
<Da...@isst.fraunhofer.de> wrote:

> Hello again,

Hi!

> ah, of course I forgot to mention that our code should run in IE9,  
> sadly. (I wouldn't prefer that). And IE9 doesn't seem to support data  
> attributes.

Data attributes are attributes like any other. IE9's JavaScript may not  
provide direct support for reading them, but jQuery and other JavaScript  
frameworks will cover that for you.

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

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


AW: AW: How to send additional data with an ajax response

Posted by "Poggenpohl, Daniel" <Da...@isst.fraunhofer.de>.
Hello again,

ah, of course I forgot to mention that our code should run in IE9, sadly. (I wouldn't prefer that). And IE9 doesn't seem to support data attributes.

Regards,
Daniel P.

-----Ursprüngliche Nachricht-----
Von: Poggenpohl, Daniel [mailto:Daniel.Poggenpohl@isst.fraunhofer.de] 
Gesendet: Freitag, 30. Oktober 2015 10:45
An: Tapestry users
Betreff: AW: AW: How to send additional data with an ajax response

Hello,

sorry, when I wrote the question I had totally forgotten about your post.
So you mean the HTML5 method of having, for example, a div element like this:
<div data-additionalData="myData"> ?

If you meant that, I haven't used this method yet for anything. Wouldn't that bloat the sent source if the additionalData is a big JSONArray? (I do not know anything about data tags yet, will inform myself)

Regards,
Daniel P.

-----Ursprüngliche Nachricht-----
Von: Thiago H de Paula Figueiredo [mailto:thiagohp@gmail.com]
Gesendet: Donnerstag, 29. Oktober 2015 12:40
An: Tapestry users
Betreff: Re: AW: How to send additional data with an ajax response

On Thu, 29 Oct 2015 05:59:30 -0200, Poggenpohl, Daniel <Da...@isst.fraunhofer.de> wrote:

> Hello,
>
> do you have example code returning not only the body, but also 
> additional data, for me?

Have you even considered my suggestion of using data tags inside the rendered HTML to provide the data?

--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer http://machina.com.br

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


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

AW: AW: How to send additional data with an ajax response

Posted by "Poggenpohl, Daniel" <Da...@isst.fraunhofer.de>.
Hello,

sorry, when I wrote the question I had totally forgotten about your post.
So you mean the HTML5 method of having, for example, a div element like this:
<div data-additionalData="myData"> ?

If you meant that, I haven't used this method yet for anything. Wouldn't that bloat the sent source if the additionalData is a big JSONArray? (I do not know anything about data tags yet, will inform myself)

Regards,
Daniel P.

-----Ursprüngliche Nachricht-----
Von: Thiago H de Paula Figueiredo [mailto:thiagohp@gmail.com] 
Gesendet: Donnerstag, 29. Oktober 2015 12:40
An: Tapestry users
Betreff: Re: AW: How to send additional data with an ajax response

On Thu, 29 Oct 2015 05:59:30 -0200, Poggenpohl, Daniel <Da...@isst.fraunhofer.de> wrote:

> Hello,
>
> do you have example code returning not only the body, but also 
> additional data, for me?

Have you even considered my suggestion of using data tags inside the rendered HTML to provide the data?

--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer http://machina.com.br

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


Re: AW: How to send additional data with an ajax response

Posted by Chris Poulsen <ma...@nesluop.dk>.
I haven't checked out all of the callback types, but we often use the
javascript callback to do extra stuff on the calling page.

Something like:

ajaxResponseRenderer.addCallback( new JavaScriptCallback()
{
    @Override
    public void run( JavaScriptSupport javascriptSupport )
    {
        javascriptSupport.require( "<module-name>" ).invoke(
"<method-name>).with(
<data-to-return-must-match-invoked-module-method-signature);
    }
} );

This does not plug into the ajax complete event, but will be executed as
part of the call returning. There is a json callback as well, but I have
not looked into what is supposed to receive its return data.

-- 
Chris

On Thu, Oct 29, 2015 at 12:40 PM, Thiago H de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> On Thu, 29 Oct 2015 05:59:30 -0200, Poggenpohl, Daniel <
> Daniel.Poggenpohl@isst.fraunhofer.de> wrote:
>
> Hello,
>>
>> do you have example code returning not only the body, but also additional
>> data, for me?
>>
>
> Have you even considered my suggestion of using data tags inside the
> rendered HTML to provide the data?
>
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: AW: How to send additional data with an ajax response

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Thu, 29 Oct 2015 05:59:30 -0200, Poggenpohl, Daniel  
<Da...@isst.fraunhofer.de> wrote:

> Hello,
>
> do you have example code returning not only the body, but also  
> additional data, for me?

Have you even considered my suggestion of using data tags inside the  
rendered HTML to provide the data?

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

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


AW: How to send additional data with an ajax response

Posted by "Poggenpohl, Daniel" <Da...@isst.fraunhofer.de>.
Hello,

do you have example code returning not only the body, but also additional data, for me?

Regards,
Daniel

-----Ursprüngliche Nachricht-----
Von: Chris Poulsen [mailto:mailinglist@nesluop.dk] 
Gesendet: Mittwoch, 28. Oktober 2015 22:16
An: Tapestry users
Betreff: Re: How to send additional data with an ajax response

Ajax response renderer may also be a viable solution for returning multiple things. I tend to prefer that over returning getBody() for exactly that reason.

--
Chris


On Wed, Oct 28, 2015 at 2:05 PM, Thiago H de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> On Wed, 28 Oct 2015 08:16:21 -0200, Poggenpohl, Daniel <
> Daniel.Poggenpohl@isst.fraunhofer.de> wrote:
>
> Hello everyone,
>>
>
> Hi!
>
> we have a problem where we update some page with an ajax request, but need
>> additional data to be sent with the ajax response. This additional data
>> should then be consumed on the client side by an ajaxComplete event. Does
>> anyone know how a Tapestry event method can return more than just getBody()
>> in the response?
>>
>
> Why don't you use data attributes in the returned HTML instead?
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: How to send additional data with an ajax response

Posted by Chris Poulsen <ma...@nesluop.dk>.
Ajax response renderer may also be a viable solution for returning multiple
things. I tend to prefer that over returning getBody() for exactly that
reason.

-- 
Chris


On Wed, Oct 28, 2015 at 2:05 PM, Thiago H de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> On Wed, 28 Oct 2015 08:16:21 -0200, Poggenpohl, Daniel <
> Daniel.Poggenpohl@isst.fraunhofer.de> wrote:
>
> Hello everyone,
>>
>
> Hi!
>
> we have a problem where we update some page with an ajax request, but need
>> additional data to be sent with the ajax response. This additional data
>> should then be consumed on the client side by an ajaxComplete event. Does
>> anyone know how a Tapestry event method can return more than just getBody()
>> in the response?
>>
>
> Why don't you use data attributes in the returned HTML instead?
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: How to send additional data with an ajax response

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Wed, 28 Oct 2015 08:16:21 -0200, Poggenpohl, Daniel  
<Da...@isst.fraunhofer.de> wrote:

> Hello everyone,

Hi!

> we have a problem where we update some page with an ajax request, but  
> need additional data to be sent with the ajax response. This additional  
> data should then be consumed on the client side by an ajaxComplete  
> event. Does anyone know how a Tapestry event method can return more than  
> just getBody() in the response?

Why don't you use data attributes in the returned HTML instead?

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

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