You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by iberck <ib...@gmail.com> on 2010/11/09 09:07:47 UTC

Diference between addInit and addScript

Hello forum, I have a question

What is the diference between renderSupport.addInit(); and
renderSupport.addScript(); 
since two methods adds a javascript function that runs on dom loaded

Thanks in advance

-- 
View this message in context: http://tapestry.1045711.n5.nabble.com/Diference-between-addInit-and-addScript-tp3256418p3256418.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Diference between addInit and addScript

Posted by Nicolas Barrera <nb...@gmail.com>.
so RenderSupport is deprecated, the use of addScript is discouraged and I
think I 've learned something new...

thanks Howard,

Nicolás.-


On Tue, Nov 9, 2010 at 10:58 PM, Howard Lewis Ship <hl...@gmail.com> wrote:

>  defined on the Tapestry.Initializer object, to be executed with a
> set of parameters.
>

Re: Diference between addInit and addScript

Posted by Howard Lewis Ship <hl...@gmail.com>.
Sorry, Nicolas, you are quite wrong.

The difference is that using RenderSupport. addScript() you are adding raw
JavaScript that gets executed when the page loads.

When using RenderSupport.addInit() you are referencing client-side
functions, defined on the Tapestry.Initializer object, to be executed with a
set of parameters.

Note 1: You should be using JavaScriptSupport in Tapestry 5.2 which is a
replacement for RenderSupport (which is deprecated).

Note 2: Using RenderSupport.addInit() /
JavaScriptSupport.addInitializerCall() allows you to write the bulk of your
page initialization as a static JavaScript library, with just a minimal
amount of per-page initialization. You also get some control over when that
initialization occurs, and you get (for free) some exception catching and
reporting if the initialization fails.

Having big blocks of JavaScript as ugly literals inside a Tapestry page is a
design smell: it should be turned into client-side JS in a library, and
calls to JavaScriptSupport.addInitializerCall().



On Tue, Nov 9, 2010 at 5:31 PM, Nicolas Barrera <nb...@gmail.com> wrote:

> The execution moment difference is a consequence of the
>
> only real difference, which afaik is how they add the script, one as
> handler
> of the on load event (add init),
>
> the other just as a <script> tag right before closing the body tag.
>
> perhaps anyone else can confirm this is the only difference,
>
> bye
>
> Nicolás.-
>
>
> On Tue, Nov 9, 2010 at 6:55 PM, iberck <ib...@gmail.com> wrote:
>
> >
> > Thank you for your responses
> >
> > So, is the execution moment the only diference ?
> >
> > Thanks in advance guys
> > --
> > View this message in context:
> >
> http://tapestry.1045711.n5.nabble.com/Diference-between-addInit-and-addScript-tp3256418p3257752.html
> > Sent from the Tapestry - User mailing list archive at Nabble.com.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>



-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to learn
how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

Re: Diference between addInit and addScript

Posted by Nicolas Barrera <nb...@gmail.com>.
The execution moment difference is a consequence of the

only real difference, which afaik is how they add the script, one as handler
of the on load event (add init),

the other just as a <script> tag right before closing the body tag.

perhaps anyone else can confirm this is the only difference,

bye

Nicolás.-


On Tue, Nov 9, 2010 at 6:55 PM, iberck <ib...@gmail.com> wrote:

>
> Thank you for your responses
>
> So, is the execution moment the only diference ?
>
> Thanks in advance guys
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/Diference-between-addInit-and-addScript-tp3256418p3257752.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Diference between addInit and addScript

Posted by iberck <ib...@gmail.com>.
Thank you for your responses

So, is the execution moment the only diference ?

Thanks in advance guys
-- 
View this message in context: http://tapestry.1045711.n5.nabble.com/Diference-between-addInit-and-addScript-tp3256418p3257752.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Diference between addInit and addScript

Posted by françois facon <fr...@gmail.com>.
Some components need specific js init.
if you have a look inside Tapestry.js and search for Tapestry.Initializer

you will find

/** Container of functions that may be invoked by the Tapestry.init()
function. */
Tapestry.Initializer = {

 ajaxFormLoop : function(spec)
    {
....    },

and lots of function.

So when ajaxFormLoop for exemple do
 void cleanupRender()
    {
        popContext();

        JSONObject spec = new JSONObject();

        spec.put("rowInjector", rowInjector.getClientId());
        spec.put("addRowTriggers", addRowTriggers);

        renderSupport.addInit("ajaxFormLoop", spec);
    }

 produce to call to ajaxFormLoop define in Tapestry.Initializer at browser
side







2010/11/9 Nicolas Barrera <nb...@gmail.com>

> I believe the difference is that
>
> addInit
>
> adds your javascript on an onLoad event handler of the current page.
>
>
> while
>
> addScript
>
> adds your javascript at the very bottom of the page (last element before
> closing body), within a <script> tag in which many components of the
> current
> page can add javascript there.
>
> I think the difference is the moment when javascript will be executed, with
> addInit in the moment the page finishes loading and with addScript whenever
> the browser reaches the <script> tag.
>
> as i see it, javascript added with addScript is executed before the one
> added with addInit.
>
>
> hope that helps, and hope not being wrong :)
>
> cheers
>
> Nicolás.-
>
>
> On Tue, Nov 9, 2010 at 5:07 AM, iberck <ib...@gmail.com> wrote:
>
> >
> > Hello forum, I have a question
> >
> > What is the diference between renderSupport.addInit(); and
> > renderSupport.addScript();
> > since two methods adds a javascript function that runs on dom loaded
> >
> > Thanks in advance
> >
> > --
> > View this message in context:
> >
> http://tapestry.1045711.n5.nabble.com/Diference-between-addInit-and-addScript-tp3256418p3256418.html
> > Sent from the Tapestry - User mailing list archive at Nabble.com.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>

Re: Diference between addInit and addScript

Posted by Nicolas Barrera <nb...@gmail.com>.
I believe the difference is that

addInit

adds your javascript on an onLoad event handler of the current page.


while

addScript

adds your javascript at the very bottom of the page (last element before
closing body), within a <script> tag in which many components of the current
page can add javascript there.

I think the difference is the moment when javascript will be executed, with
addInit in the moment the page finishes loading and with addScript whenever
the browser reaches the <script> tag.

as i see it, javascript added with addScript is executed before the one
added with addInit.


hope that helps, and hope not being wrong :)

cheers

Nicolás.-


On Tue, Nov 9, 2010 at 5:07 AM, iberck <ib...@gmail.com> wrote:

>
> Hello forum, I have a question
>
> What is the diference between renderSupport.addInit(); and
> renderSupport.addScript();
> since two methods adds a javascript function that runs on dom loaded
>
> Thanks in advance
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/Diference-between-addInit-and-addScript-tp3256418p3256418.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>