Paul,

What you are describing is exactly what RenderSupport (5.1) and
JavaScriptSupport (5.2) are for ... they allow you, during the render,
to identify any JavaScript that should execute once the DOM is fully
loaded. In other words, avoid inline <script> blocks and "javascript:"
URLs in tag attribute, and perform the equivalent using
JavaScriptSupport.

The general approach is to add a new function to the
Tapestry.Initializer namespace (on the client), and then use
JavaScriptSupport.addInitializerCall() to request that the function be
invoked, passing either a String or a JSONObject to the client.

You'll see a blog of JavaScript just before the </body>, that's where
all the initializer calls accumulate.

The APIs exist to encourage you to structure your JavaScript properly:
mostly static JavaScript coming from library files that may be cached
by the client web browser, with a minimal amount of page-specific
initialization to get the ball rolling.  Doing it the correct,
Tapestry, way ensures that your components will operate correctly
during a full page render, but also during a partial page render (as
part of an Ajax request).

On Mon, Mar 7, 2011 at 6:23 PM, Paul Stanton <p...@mapshed.com.au> wrote:
> Yes I get your point,
>
> I feel that what I'm suggesting is an improvement on something that exists
> in the project or at least an enhanced version of something that already
> exists: "waitForPage".
>
> I thought that if tapestry were enough of a "general purpose javascript
> library" to implement "waitForPage" then it would also make sense for it to
> implement the functionality I'm suggesting. The functionality cannot be
> found in prototype or any other javascript library since it relies on
> Tapestry.pageLoaded and Tapestry.onDOMLoaded.
>
> A summary of the issue I'm trying to solve:
>
> I have a javascript function which can be called in multiple scenarios and
> within it, sets an element's innerHTML. It is called by some rendering code
> (which would make sense to use RenderSupport.addScript) but it is also
> called from other javascript functions some of which may be render phase or
> just user event handlers.
>
> As you may know, setting innerHTML prior to page load breaks page loading in
> ie. Therefore I need to make sure this never happens prior to page load.
>
> Since there are many different calling cases It is much easier to handle the
> scenario at one point ie within the function it's self. This saves me
> changing many existing files, remodelling code and also means our developers
> don't need to worry about it in future.
>
> It is the same approach used when people use 'waitForPage'. They are saying
> "this user action is not available until the page is loaded so disallow it".
>
> p.
>
> On 8/03/2011 5:23 AM, Josh Canfield wrote:
>>
>> Hi Paul.
>>
>>> I'm not sure what you mean by that statement Josh, I'm proposing a useful
>>> utility method inseparable from the tapestry js api so that other users
>>> don't have to write and embed the method themselves also.
>>
>> What I'm saying is that Tapestry isn't a general purpose javascript
>> library. As Thiago has pointed out there are features in the framework
>> that allow you to inject javascript into the page so that it's run at
>> the appropriate time. It sounds like you are trying to work outside of
>> these mechanisms.
>>
>> Maybe if you explained what you wanted to do from a higher level
>> someone could provide advice on how to accomplish your goals within
>> the framework.
>>
>> Josh
>>
>> On Sun, Mar 6, 2011 at 3:52 PM, Paul Stanton<p...@mapshed.com.au>  wrote:
>>>
>>> "I don't think we need to replicate functionality provided by javascript
>>> libraries."
>>>
>>> Tapestry provides onDOMLoaded and waitForPage .. the functionality I
>>> describe isn't provided by Tapestry or a javascript library (since the js
>>> lib would need to know about the Tapestry js api).
>>>
>>> I'm not sure what you mean by that statement Josh, I'm proposing a useful
>>> utility method inseparable from the tapestry js api so that other users
>>> don't have to write and embed the method themselves also.
>>>
>>> p.
>>>
>>> On 7/03/2011 10:44 AM, Josh Canfield wrote:
>>>>>
>>>>> seems to work, but I can see the need to make the callbacks
>>>>> parameterised
>>>>> in
>>>>> the future (which currently isn't supported by Tapestry.onDOMLoaded)
>>>>
>>>> Callbacks are closures, why do you need parameters?
>>>>
>>>>> If something like this doesn't exist in tapestry already, I think it
>>>>> should.
>>>>
>>>> I don't think we need to replicate functionality provided by
>>>> javascript libraries.
>>>>
>>>> Josh
>>>>
>>>> On Sun, Mar 6, 2011 at 3:12 PM, Paul Stanton<p...@mapshed.com.au>
>>>>  wrote:
>>>>>
>>>>> In lieu of a better (tapestry provided) solution, this is what i'm
>>>>> using.
>>>>> It
>>>>> seems to work, but I can see the need to make the callbacks
>>>>> parameterised
>>>>> in
>>>>> the future (which currently isn't supported by Tapestry.onDOMLoaded)
>>>>>
>>>>> function callWhenPageLoaded(callback)
>>>>> {
>>>>>    if (typeof(Tapestry) == "undefined")
>>>>>        throw("callWhenPageLoaded called too early");
>>>>>
>>>>>    if (Tapestry.pageLoaded)
>>>>>        callback.call(this);
>>>>>    else
>>>>>        Tapestry.onDOMLoaded(callback);
>>>>> }
>>>>>
>>>>> If something like this doesn't exist in tapestry already, I think it
>>>>> should.
>>>>>
>>>>> p.
>>>>>
>>>>> On 7/03/2011 9:44 AM, Paul Stanton wrote:
>>>>>>
>>>>>> Hi all,
>>>>>>
>>>>>> i'm using tapestry 5.1.0.5 on this particular project.
>>>>>>
>>>>>> I'm not 100% sure this isn't already available, but before duplicating
>>>>>> logic i thought I'd check...
>>>>>>
>>>>>> I need to be able to call a function at any point in the page state
>>>>>> (ie
>>>>>> before it's loaded, during loading, after load) but have it wait until
>>>>>> tapestry.init has been called.
>>>>>>
>>>>>> Kind of how Tapestry.waitForPage works, except that if the page has
>>>>>> not
>>>>>> loaded, instead of showing a dialog, it would register it for invoking
>>>>>> once
>>>>>> the page is loaded.
>>>>>>
>>>>>> so in psuedo:
>>>>>>
>>>>>> function(callback)
>>>>>> {
>>>>>>    if(Tapestry.pageLoaded)
>>>>>>        invoke(callback);
>>>>>>    else
>>>>>>        Tapestry.onDOMLoaded(callback);
>>>>>> }
>>>>>>
>>>>>> 2 questions:
>>>>>> a) is this functionality already available? where?
>>>>>> b) would the above approach be fool-proof? ie would there be a case
>>>>>> where
>>>>>> Tapestry.pageLoaded == false and Tapestry.onDOMLoaded would still not
>>>>>> invoke
>>>>>> the callback?
>>>>>>
>>>>>> thanks, p.
>>>>>>
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
>>>>>> For additional commands, e-mail: users-h...@tapestry.apache.org
>>>>>>
>>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
>>>>> For additional commands, e-mail: users-h...@tapestry.apache.org
>>>>>
>>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
>>>> For additional commands, e-mail: users-h...@tapestry.apache.org
>>>>
>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
>>> For additional commands, e-mail: users-h...@tapestry.apache.org
>>>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
>> For additional commands, e-mail: users-h...@tapestry.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@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

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

Reply via email to