Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Javascript Function "Undefined" in HTMLFlow

    I have some html that I put into an HTML flow which contains javascript. When I attempt to call the function on a Window that contains the HTMLFlow, I see the following exception:

    Uncaught JavaScript exception [foo is not defined] in http://localhost:8080/gsui/?gwt.codesvr=127.0.0.1:9997, line 1

    Reading the documentation, I see that using setEvalScriptBlocks(true) evalutes script blocks so that the HTML functions like a normal HTML page would?

    What am I doing wrong?

    Code:
    public class Page extends HTMLFlow
    {
        public Page()
        {
            super();
            doLayout();
        }
        
        private void doLayout()
        {
            String html = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" +
                    "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
                    "<head>\n" +
                    "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n" +
                    "<script type=\"text/javascript\">\n" +
                    "\tfunction foo()\n" +
                    "\t{\n" +
                    "\t\talert('foo');\n" +
                    "\t}\n" +
                    "</script>\n" +
                    "<title>Untitled Document</title>\n" +
                    "</head>\n" +
                    "\n" +
                    "<body>\n" +
                    "<input type=\"button\" onclick=\"foo();\"  value=\"Shoot\"/>\n" +
                    "</body>\n" +
                    "</html>\n";
            setEvalScriptBlocks(true);
            setContents(html);
            setContentsType(ContentsType.PAGE);
        }
    }

    #2
    evalScriptBlocks currently only applies to content loaded via contentsURL, not to content applied via setContents(). Also, contentsType.page, which creates an iframe, does not make sense with setContents().

    Comment


      #3
      What approach would you recommend to be able to access these functions using an HTMLFlow? Should I be using JSNI?

      Here is my use case:

      I have a custom browser plugin that I have to include in my application. Several instances of these plugins will be made available to users via an HTMLFlow that sits inside a window, which sits in a canvas.
      I need a way to work with each instance dynamically through javascript, so I have to be able to write the javascript in the HTMLFlow and use setContents. It is unclear yet weather the buttons that will control the plugin will be part of the HTMLFlow or be implemented as SmartGWT buttons in, say an HLayout below the HTMLFlow.

      I'm having a difficult time setting this up.

      Thanks,
      Last edited by ls3674; 15 Mar 2012, 11:31.

      Comment


        #4
        Yes, rather than trying to embed the JavaScript functions into the HTMLFlow alongside the plugin, you are better off using JSNI. Among many other problems, if there are multiple such plugins, they are presumably each going to write out similar JavaScript methods, and clobber each other.

        You are also much better off creating any interactive components as true SmartGWT components, such that your overall portlet might consist of a VLayout containing the HTMLFlow along with several related buttons and other controls.

        Comment

        Working...
        X