You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Paul Stanton <pa...@mapshed.com.au> on 2013/04/19 03:28:52 UTC

mixing script added in afterrender not fired for xhr requests

Hi all,

Can someone familiar with the mixin lifecycle please advise me:

I have a mixin which triggers some javascript from 'afterRender'. I do 
this in 'afterRender' because I need the field's clientId to be initialised.

It works great if the Field it attaches to is rendered when the page is 
first rendered, however if it is rendered as part of a zone update/xhr 
request, the script is never sent to the client.

I have breakpointed the JavaScriptCallback and while it is successfully 
added to the ajaxResponseRenderer, it is never called.

Thanks for advice!


code Eg:

public class MyMixin
{
     ...

     void afterRender()
     {
         addScript("MyMixin.create('%s', '%s');", field.getClientId(), 
myVariable);
     }

     private void addScript(final String format, final Object... args)
     {
         if (!request.isXHR())
         {
             jsSupport.addScript(InitializationPriority.NORMAL, format, 
args);
             return;
         }

         ajaxResponseRenderer.addCallback(new JavaScriptCallback()
         {
             @Override
             public void run(JavaScriptSupport javascriptSupport)
             {
javascriptSupport.addScript(InitializationPriority.NORMAL, format, args);
             }
         });
     }
}

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


Re: mixin script added in afterrender not fired for xhr requests

Posted by Paul Stanton <pa...@mapshed.com.au>.
Actually, no .. I cannot just use "JavascriptSupport.addScript" 
everywhere I used to use "AjaxResponseRenderer.addCallback"

In XHR cases I get: UnknownValueException - "No object of type 
org.apache.tapestry5.services.javascript.JavaScriptSupport is available 
from the Environment."

I wonder why this is not the case in the Mixin's afterRender.. ?

This is getting confusing because calling 
"AjaxResponseRenderer.addCallback" does not work in the case of the 
"Mixin.afterRender", however "JavascriptSupport" does not work in XHR 
event handlers.

I imagine this has to do with the render phase somehow... would love to 
hear some experts opinion...

thanks, p.

On 24/04/2013 2:40 PM, Paul Stanton wrote:
> Turned out this was because I was adding the script via 
> "ajaxResponseRenderer.addCallback" which used to be the recommended 
> approach.
>
> JavascriptSupport now handles partial renders via "partialMode" (if 
> you look at the source).
>
> Perhaps "ajaxResponseRenderer.addCallback" should be deprecated now?
>
> p.
>
> On 22/04/2013 11:56 AM, Paul Stanton wrote:
>> Feel free to answer on StackOverflow and I will give you the rep points.
>>
>> http://stackoverflow.com/questions/16138055/mixin-script-added-in-afterrender-not-fired-for-xhr-requests 
>>
>>
>> On 21/04/2013 4:05 PM, Paul Stanton wrote:
>>> this is tapestry 5.3
>>>
>>> On 19/04/2013 11:28 AM, Paul Stanton wrote:
>>>> Hi all,
>>>>
>>>> Can someone familiar with the mixin lifecycle please advise me:
>>>>
>>>> I have a mixin which triggers some javascript from 'afterRender'. I 
>>>> do this in 'afterRender' because I need the field's clientId to be 
>>>> initialised.
>>>>
>>>> It works great if the Field it attaches to is rendered when the 
>>>> page is first rendered, however if it is rendered as part of a zone 
>>>> update/xhr request, the script is never sent to the client.
>>>>
>>>> I have breakpointed the JavaScriptCallback and while it is 
>>>> successfully added to the ajaxResponseRenderer, it is never called.
>>>>
>>>> Thanks for advice!
>>>>
>>>>
>>>> code Eg:
>>>>
>>>> public class MyMixin
>>>> {
>>>>     ...
>>>>
>>>>     void afterRender()
>>>>     {
>>>>         addScript("MyMixin.create('%s', '%s');", 
>>>> field.getClientId(), myVariable);
>>>>     }
>>>>
>>>>     private void addScript(final String format, final Object... args)
>>>>     {
>>>>         if (!request.isXHR())
>>>>         {
>>>> jsSupport.addScript(InitializationPriority.NORMAL, format, args);
>>>>             return;
>>>>         }
>>>>
>>>>         ajaxResponseRenderer.addCallback(new JavaScriptCallback()
>>>>         {
>>>>             @Override
>>>>             public void run(JavaScriptSupport javascriptSupport)
>>>>             {
>>>> javascriptSupport.addScript(InitializationPriority.NORMAL, format, 
>>>> args);
>>>>             }
>>>>         });
>>>>     }
>>>> }
>>>>
>>>> ---------------------------------------------------------------------
>>>> 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
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> 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
>
>


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


Re: mixin script added in afterrender not fired for xhr requests

Posted by Paul Stanton <pa...@mapshed.com.au>.
Turned out this was because I was adding the script via 
"ajaxResponseRenderer.addCallback" which used to be the recommended 
approach.

JavascriptSupport now handles partial renders via "partialMode" (if you 
look at the source).

Perhaps "ajaxResponseRenderer.addCallback" should be deprecated now?

p.

On 22/04/2013 11:56 AM, Paul Stanton wrote:
> Feel free to answer on StackOverflow and I will give you the rep points.
>
> http://stackoverflow.com/questions/16138055/mixin-script-added-in-afterrender-not-fired-for-xhr-requests 
>
>
> On 21/04/2013 4:05 PM, Paul Stanton wrote:
>> this is tapestry 5.3
>>
>> On 19/04/2013 11:28 AM, Paul Stanton wrote:
>>> Hi all,
>>>
>>> Can someone familiar with the mixin lifecycle please advise me:
>>>
>>> I have a mixin which triggers some javascript from 'afterRender'. I 
>>> do this in 'afterRender' because I need the field's clientId to be 
>>> initialised.
>>>
>>> It works great if the Field it attaches to is rendered when the page 
>>> is first rendered, however if it is rendered as part of a zone 
>>> update/xhr request, the script is never sent to the client.
>>>
>>> I have breakpointed the JavaScriptCallback and while it is 
>>> successfully added to the ajaxResponseRenderer, it is never called.
>>>
>>> Thanks for advice!
>>>
>>>
>>> code Eg:
>>>
>>> public class MyMixin
>>> {
>>>     ...
>>>
>>>     void afterRender()
>>>     {
>>>         addScript("MyMixin.create('%s', '%s');", 
>>> field.getClientId(), myVariable);
>>>     }
>>>
>>>     private void addScript(final String format, final Object... args)
>>>     {
>>>         if (!request.isXHR())
>>>         {
>>>             jsSupport.addScript(InitializationPriority.NORMAL, 
>>> format, args);
>>>             return;
>>>         }
>>>
>>>         ajaxResponseRenderer.addCallback(new JavaScriptCallback()
>>>         {
>>>             @Override
>>>             public void run(JavaScriptSupport javascriptSupport)
>>>             {
>>> javascriptSupport.addScript(InitializationPriority.NORMAL, format, 
>>> args);
>>>             }
>>>         });
>>>     }
>>> }
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>>
>
>
> ---------------------------------------------------------------------
> 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


Re: mixin script added in afterrender not fired for xhr requests

Posted by Paul Stanton <pa...@mapshed.com.au>.
Feel free to answer on StackOverflow and I will give you the rep points.

http://stackoverflow.com/questions/16138055/mixin-script-added-in-afterrender-not-fired-for-xhr-requests

On 21/04/2013 4:05 PM, Paul Stanton wrote:
> this is tapestry 5.3
>
> On 19/04/2013 11:28 AM, Paul Stanton wrote:
>> Hi all,
>>
>> Can someone familiar with the mixin lifecycle please advise me:
>>
>> I have a mixin which triggers some javascript from 'afterRender'. I 
>> do this in 'afterRender' because I need the field's clientId to be 
>> initialised.
>>
>> It works great if the Field it attaches to is rendered when the page 
>> is first rendered, however if it is rendered as part of a zone 
>> update/xhr request, the script is never sent to the client.
>>
>> I have breakpointed the JavaScriptCallback and while it is 
>> successfully added to the ajaxResponseRenderer, it is never called.
>>
>> Thanks for advice!
>>
>>
>> code Eg:
>>
>> public class MyMixin
>> {
>>     ...
>>
>>     void afterRender()
>>     {
>>         addScript("MyMixin.create('%s', '%s');", field.getClientId(), 
>> myVariable);
>>     }
>>
>>     private void addScript(final String format, final Object... args)
>>     {
>>         if (!request.isXHR())
>>         {
>>             jsSupport.addScript(InitializationPriority.NORMAL, 
>> format, args);
>>             return;
>>         }
>>
>>         ajaxResponseRenderer.addCallback(new JavaScriptCallback()
>>         {
>>             @Override
>>             public void run(JavaScriptSupport javascriptSupport)
>>             {
>> javascriptSupport.addScript(InitializationPriority.NORMAL, format, 
>> args);
>>             }
>>         });
>>     }
>> }
>>
>> ---------------------------------------------------------------------
>> 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
>
>


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


Re: mixin script added in afterrender not fired for xhr requests

Posted by Paul Stanton <pa...@mapshed.com.au>.
this is tapestry 5.3

On 19/04/2013 11:28 AM, Paul Stanton wrote:
> Hi all,
>
> Can someone familiar with the mixin lifecycle please advise me:
>
> I have a mixin which triggers some javascript from 'afterRender'. I do 
> this in 'afterRender' because I need the field's clientId to be 
> initialised.
>
> It works great if the Field it attaches to is rendered when the page 
> is first rendered, however if it is rendered as part of a zone 
> update/xhr request, the script is never sent to the client.
>
> I have breakpointed the JavaScriptCallback and while it is 
> successfully added to the ajaxResponseRenderer, it is never called.
>
> Thanks for advice!
>
>
> code Eg:
>
> public class MyMixin
> {
>     ...
>
>     void afterRender()
>     {
>         addScript("MyMixin.create('%s', '%s');", field.getClientId(), 
> myVariable);
>     }
>
>     private void addScript(final String format, final Object... args)
>     {
>         if (!request.isXHR())
>         {
>             jsSupport.addScript(InitializationPriority.NORMAL, format, 
> args);
>             return;
>         }
>
>         ajaxResponseRenderer.addCallback(new JavaScriptCallback()
>         {
>             @Override
>             public void run(JavaScriptSupport javascriptSupport)
>             {
> javascriptSupport.addScript(InitializationPriority.NORMAL, format, args);
>             }
>         });
>     }
> }
>
> ---------------------------------------------------------------------
> 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