Flex IFrame library - Duplicate reload issue and multiple IFrames problem.

Issue 1 : Flex IFrame Duplicate reload


At times the Flex- IFrame library recreates the IFrame with the same URL. This may be due to a possible bug in the application which creates the event to cause the IFrame to reload when not required.

Whatsoever may be the root cause, but this duplicate IFrame creation reloads the URL which was already loaded, which in turn sends a http request to server.

This will unwanted server load, logging, and duplicate database read/write is a performance and integrity threat.

Solution


The actual solution may be to find the unnecessary events which trigger the IFrame creation call. But this will not guarantee that no such new code
will not be introduced in the future.

The better solution would be to check the current IFrame source and the new IFrame source before loading the IFrame.

A subclass of class com.google.code.flexiframe.IFrame is created and overridden the default behavior of the loadIFrame () as below.

This is how Inheritance helps us to alter the functionality of certain methods without affecting the whole class.
/**
     * Custom Iframe to prevent
     * Loading of the same url mulitple times.
     * This will load the iframe only when a
     * new url is assinged to the IFrame. 
     * Otherwise IFrame will not be loaded,
     * hence duplicate calls to the server will be prevented.
     */
 public class CustomIFrame extends IFrame
 {
  private var currUrl:String;
  public function CustomIFrame()
  {
   super();     
  }
  /**
      * Don't trigger the IFrame load call
      * if current source and new source is 
         * same. Prevent duplicate calls.
         */
  override protected function loadIFrame():void{
   
   if(this.source != currUrl){
    super.loadIFrame();
   }
   currUrl = source;
  }
 }
    Use the new CustomeIframe class in mxml or actioin script
   
    <components:CustomIFrame id="someId" height="100%" width="100%"/>

    var IFrame iFrame = new CustomIFrame();

Issue 2 : Multiple IFrames in a single HTML.


When you have mutliple IFrames in the same HTML, or the page where you want to add the Flex-IFrame is already running inside an IFrame, you may
encoutner Id issues, and the flex-iframe may not be properly placed.

Solution


To avoid this place your main mxml inside its own IFrame. This will resolve id conflict issues.

<iframe width="100%" height="100%" src="mainmxml.jsp?" frameborder="0"></iframe>
Here mainmxml.jsp is  your activex object

Comments

Popular posts from this blog

Log4j multiple WAR files in single EAR configuration

Java NIO2 - Watching a directory for changes. FileWatcherService.

Ubuntu Add programs to launcher (Desktop)