Troy Ballantine

Greenhorn
+ Follow
since Oct 31, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Troy Ballantine

I wanted to post this because I searched for an answer to this over 2 years ago and didn't find one. I just search today and didn't either. I found two old postings on the JavaRanch from back in 2007 and neither of them had what I would call an elegant solution. I think I finally have a pseudo-elegant solution and I want to see if anyone can poke holes in it.

The issue is that I want to move javascript out of my jsp into a js file in a portlet based application. Since I am dealing with portlets then I still needed to be able to portlet namespsace my javascript methods and variables so that I would not step on the toes of other portlets. Given this issue we had a lot of duplicate javascript code. The answer was staring me in the face because we had already instituted something that would work for our company javascript library that was based on jQuery. I templated it today and call it AJL (Application Javascript Library). The developers will be able to copy the AJL code template you will see below into their portlet application and start coding.

Here is the template:



Here is my test html. I did not do portlet code because we are using this "design" already in production so that is tested out.



Once I have it out in a js file I can also minify it which is something I could not do if I went the include jsp route. This solution also addresses an issue a developer is having here in that a compiled JSP exceeded some size limit. I won't go into the whole design of the page since it could be argued it is too big but being able to remove the JS will help solve that for him. If we did an include JSP mechanism it still would have been part of the compiled page.

Please let me know what you think.
13 years ago