advertisement
javaboutique
Search Tips
Articles  |   Tutorials  |   Reviews  |   Tools  |   by Category  |   by Date  |   by Name  |   Submit  |   Source  |   Forums  |  
javaboutique
Browse DevX


Partners & Affiliates











advertisement

JavaBoutique : Articles :

Cracking the HTML Persistence Barrier

Contents
Introduction
Intro pt 1
Intro pt 2
Intro pt 3
Intro pt 4
An Illustration of these Techniques
An Applet Example
An Active X Example
A Pseudo-Constructor Example
Pseudo-Constructor pt 2
Applet Persists Indefinitely; Breaks into JavaScript
Persistence
Conclusion

If one looks at abstract classes in JAVA, one notices that they are tied very closely to the JAVA virtual machine. If they could be instantiated, then certainly they would persist – programs could then be remembered along with data, even when the applet was inactive. However, abstract classes cannot contain constructors. Suppose, however (sample code is presented further on), that applet code is composed solely of pointers to static variables defined in some abstract class. Suppose further that static components for a frame (buttons, etc.), as well as the static name of the frame itself, are also defined in the abstract class.

Then, suppose that init() in the applet calls a static function in the abstract class which instantiates the static frame and assigns the static components to it. It then sets a flag in the abstract class that tells it not to do this again. One now has a kind of pseudo-constructor for the abstract class. The resulting frame, and its components, are tied, through the abstract class, to the JAVA virtual machine itself, and they persist from HTML page to HTML page, even when the applet is not being loaded. The applet that originally launched both the frame and the abstract class may itself move back and forth from an active to an inactive state, as the user browses from one HTML page to another, but this makes no difference to the frame itself, for it is no longer dependent upon the applet.

Now, how do we enable events within this 'terminate and stay resident' frame – so that it will carry out actions when 'off site'? It is done in the following manner (sample code follows). Events must be caught in the frame itself, but all variables and interrupt methods are contained as static variables and static methods in the abstract class. The frame event handlers simply make jumps to these static variables and methods. Through a use of these two separate persistence techniques – loading a program repeatedly, and forming a pseudo-constructor for an abstract class - we have now created a program that lives beyond the page in which it was launched, remembers data that is collected from page to page for as long as a page accesses the launching applet through a relative call, and carries out event handling within the frame itself, on applet data, when off-site.

The JAVA program has now broken away from the launching page, and it ‘lives forever.’ It is interesting to reduce the browser to a partial window, and to place the shopping cart frame on the desktop beside it. Browse from page to page, and watch the frame. It doesn’t flicker. The buttons continue to work. JAVA in the frame is fully enabled at all times. As we will see later, it is possible, in some browsers, to break into the HTML, from the frame, and to interact with JavaScript on every subsequent page.

There is one restriction. If you are running JAVA off-site – that is, if you force the cart to do something by pressing a button, and if the resulting event-handling uses ‘new’ to create a variable, and if at the same time the browser is working very hard at loading a page, then it is theoretically possible to crash the browser. The solution is simple: avoid the use of ‘new’ when off-site. (This step has not yet been taken with the shopping cart program because in part it involves the use of global static variables, and these make further program development very difficult.)

Next ->


Lane Friesen

lanelise@dowco.com

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.

 Avaya Developer Showcase
 MSDN Spotlight
 PHP for Windows Showcase
XML error: undefined entity at line 34
advertisement
Receive Articles via our XML/RSS feed
Receive Articles via our XML/RSS feed

JavaBytes
Internet Cyclone
This powerful, easy-to-use, internet optimizer is for Windows 95, 98, ME, NT, 2000 and XP. It's designed to automatically optimize your Windows settings, boosting your Internet connection up to 200%.

IBM Brings Developers Into the Cloud
Apache at 10: You Can't Buy Us
Microsoft's CodePlex Foundation Moving Forward
Apple Claims 100,000 Apps, Google Analyzes Them
Nokia Latest to Play Opera Mobile 10 Browser
PayPal Opens Up Payment Platform to Devs
Ubuntu Linux 9.10 'Karmic Koala' Starts Its Climb
IBM Links Rational Developer Tools, Tivoli Apps
Libraries Give Vista Apps a Windows 7 Look
Ubuntu: The 'Default Alternative' to Windows?

Delivering Web-based Embedded Fonts in CSS 3
Adobe Helps PHP Developers Create Rich Internet Applications
Java Developers Finding a Home at Adobe Flex
Virtualization Delivers a Dynamic Infrastructure
Consuming XML Web Services in iPhone Applications
Build a More Agile Business with IBM
POJO-Based Solutions for LDAP Access: One Good, One Better
IBM Offers Enhanced Measurement and Management for Energy Usage
IBM Helps Transformation to an Information-Based Enterprise
Top Five Touch UI-Related Design Guidelines

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs