PDA

View Full Version : Globally Available Objects



mills.joe
Jan 5th, 2011, 10:05 AM
Is there way to set a variable in a webscript that all other webscripts have access to within a page?

Here's my situation. I want to pull down some content from and instance of Alfresco based on the incomming URL. This one call to Alfresco will contain 90% of what I need for that page. However, there will be that 10% I have to use other webscripts for. Here's the rub: these other webscripts will need to call other information based on what comes down with that main content.

Is there a way to set this main content into a variable that is available to every webscript that is used within the page object? This data does not need to live beyond the life of the page. It seems a rather large waste of overhead for me to have to slice up the url and figure out what I need within every webscript. I'd rather just do that once.

kroast
Jan 13th, 2011, 08:50 AM
Yes we do this kind of technique in Alfresco Share to cache common remote API calls for a page render but to continue to keep component isolation.

Example:

In earliest component:


context.setValue("site-title", siteTitle);

In later component:


var siteTitle = context.properties["site-title"];
if (siteTitle == null)
{
//... do the call ourselves as value not cached yet
}

Hope this helps,

Kev

chozero
Feb 10th, 2011, 07:45 AM
Great tip.

Thanks!

mills.joe
Feb 10th, 2011, 11:11 AM
Thanks so much! Great tip. I actually needed to cache some stuff so I wrote an interceptor that captures the data I needed before it hit surf, then inserted it via java. However, as I'll be using surf for several more projects your tip will be very useful.

Much thanks!