You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Wayne Pope <wa...@googlemail.com> on 2010/03/05 10:44:52 UTC

Only render javascript once per request?

Hi,

I been looking how to solve this and I cannot see a clear way.

Basically in a given page we have a list of TextField derived classes
that use a JQuery auto complete.
This means for each textfield rendered on the page we render in the
head something like:

$(document).ready(function(){var data = ['Sitemap', 'vbmbmnvbmn',
'second', 'communications', 'test', 'Wayne', 'Wireframes', 'fook',
'business case', 'Logos', 'round 1', 'layout', 'Marketing', 'new one',
'graphics', 'hot stuff', 'Accounts', 'Template'];
$('#labels390').autocomplete(data,  { multiple: true,
multipleSeparator: ', ', scroll: true, scrollHeight: 300 })})

$(document).ready(function(){var data = ['Sitemap', 'vbmbmnvbmn',
'second', 'communications', 'test', 'Wayne', 'Wireframes', 'fook',
'business case', 'Logos', 'round 1', 'layout', 'Marketing', 'new one',
'graphics', 'hot stuff', 'Accounts', 'Template'];
$('#labels391').autocomplete(data,  { multiple: true,
multipleSeparator: ', ', scroll: true, scrollHeight: 300 })})

$(document).ready(function(){var data = ['Sitemap', 'vbmbmnvbmn',
'second', 'communications', 'test', 'Wayne', 'Wireframes', 'fook',
'business case', 'Logos', 'round 1', 'layout', 'Marketing', 'new one',
'graphics', 'hot stuff', 'Accounts', 'Template'];
$('#labels392').autocomplete(data,  { multiple: true,
multipleSeparator: ', ', scroll: true, scrollHeight: 300 })})

etc..


As you can clearly see this isn't too efficient and I want to set the
data array only once and then attach the autocomplete to the textfield
and the data.

In the renderhead of the textfield derived class is there anyway to
somehow only render the data part once per request? (this also
massively reduces the db calls to create the list!)

thanks for any pointers
Wayne

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


Re: Only render javascript once per request?

Posted by Igor Vaynberg <ig...@gmail.com>.
first call renderjavascript("var="+array, "some unique id");
then call to render the javascript that uses the array

wicket will filter contributions by the "some unique id" and only the
first one will be rendered.

the second part is caching your db call. you can retrieve the db list
and store it in requestcycle's metadata as a request-scoped cache.

-igor


On Fri, Mar 5, 2010 at 1:44 AM, Wayne Pope
<wa...@googlemail.com> wrote:
> Hi,
>
> I been looking how to solve this and I cannot see a clear way.
>
> Basically in a given page we have a list of TextField derived classes
> that use a JQuery auto complete.
> This means for each textfield rendered on the page we render in the
> head something like:
>
> $(document).ready(function(){var data = ['Sitemap', 'vbmbmnvbmn',
> 'second', 'communications', 'test', 'Wayne', 'Wireframes', 'fook',
> 'business case', 'Logos', 'round 1', 'layout', 'Marketing', 'new one',
> 'graphics', 'hot stuff', 'Accounts', 'Template'];
> $('#labels390').autocomplete(data,  { multiple: true,
> multipleSeparator: ', ', scroll: true, scrollHeight: 300 })})
>
> $(document).ready(function(){var data = ['Sitemap', 'vbmbmnvbmn',
> 'second', 'communications', 'test', 'Wayne', 'Wireframes', 'fook',
> 'business case', 'Logos', 'round 1', 'layout', 'Marketing', 'new one',
> 'graphics', 'hot stuff', 'Accounts', 'Template'];
> $('#labels391').autocomplete(data,  { multiple: true,
> multipleSeparator: ', ', scroll: true, scrollHeight: 300 })})
>
> $(document).ready(function(){var data = ['Sitemap', 'vbmbmnvbmn',
> 'second', 'communications', 'test', 'Wayne', 'Wireframes', 'fook',
> 'business case', 'Logos', 'round 1', 'layout', 'Marketing', 'new one',
> 'graphics', 'hot stuff', 'Accounts', 'Template'];
> $('#labels392').autocomplete(data,  { multiple: true,
> multipleSeparator: ', ', scroll: true, scrollHeight: 300 })})
>
> etc..
>
>
> As you can clearly see this isn't too efficient and I want to set the
> data array only once and then attach the autocomplete to the textfield
> and the data.
>
> In the renderhead of the textfield derived class is there anyway to
> somehow only render the data part once per request? (this also
> massively reduces the db calls to create the list!)
>
> thanks for any pointers
> Wayne
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

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