public void render()

in tapestry-framework/src/java/org/apache/tapestry/dojo/AjaxShellDelegate.java [82:239]


    public void render(IMarkupWriter writer, IRequestCycle cycle)
    {
        // first configure dojo, has to happen before package include

        JSONObject dojoConfig = new JSONObject();

        // Debugging configuration , debugAtAlCosts causes the individual 
        // .js files to included in the document head so that javascript errors
        // are able to resolve to the context of the file instead of just "dojo.js"

        if (_debug)
        {
            dojoConfig.put("isDebug", _debug);
        }

        if (_debugAtAllCosts)
            dojoConfig.put("debugAtAllCosts", _debugAtAllCosts);
        if (_debugContainerId != null)
            dojoConfig.put("debugContainerId", _debugContainerId);

        IPage page = cycle.getPage();

        // The key to resolving everything out of the asset service

        if (_dojoPath!=null)
        {
            dojoConfig.put("baseRelativePath", _dojoPath.buildURL());
        }

        if (page.hasFormComponents())
        {
            dojoConfig.put("preventBackButtonFix", _preventBackButtonFix);
        }
        
        dojoConfig.put("parseWidgets", _parseWidgets);
        if (_searchIds != null)
            dojoConfig.put("searchIds", new JSONLiteral(_searchIds));

        // Supports setting up locale in dojo environment to match the requested page locale.
        // (for things that use these settings, like DropdownDatePicker / date parsing / etc..

        Locale locale = cycle.getPage().getLocale();

        String localeStr = locale.getLanguage().toLowerCase()
                           + ((locale.getCountry() != null && locale.getCountry().trim().length() > 0)
                              ? "-" + locale.getCountry().toLowerCase()
                              : "");

        if (isLocaleSupported(localeStr))
        {
            dojoConfig.put("locale", localeStr);
        }

        // Write the required script includes and dojo.requires

        writer.begin("script");
        writer.attribute("type", "text/javascript");
        writer.printRaw("djConfig = ");
        writer.printRaw(dojoConfig.toString());
        writer.printRaw(" ");
        writer.end();
        writer.println();
        writer.println();

        // include the core dojo.js package

        if (_dojoSource!=null)
        {
            writer.begin("script");
            writer.attribute("type", "text/javascript");
            writer.attribute("src", _dojoSource.buildURL());
            writer.end();
        }

        if (page.hasFormComponents() && _dojoFormSource!=null)
        {
            writer.begin("script");
            writer.attribute("type", "text/javascript");
            writer.attribute("src", _dojoFormSource.buildURL());
            writer.end();
        }

        if (page.hasWidgets() && _dojoWidgetSource!=null)
        {
            writer.begin("script");
            writer.attribute("type", "text/javascript");
            writer.attribute("src", _dojoWidgetSource.buildURL());
            writer.end();            
        }

        // configure basic dojo properties , logging includes

        if (_debug)
        {
            String logRequire = _consoleEnabled ? "dojo.require(\"dojo.debug.console\");"
                                : "dojo.require(\"dojo.logging.Logger\");";

            writer.println();
            writer.begin("script");
            writer.attribute("type", "text/javascript");
            writer.println();
            writer.printRaw(logRequire);
            writer.println();
            writer.printRaw("dojo.log.setLevel(dojo.log.getLevel(\"");
            writer.printRaw(_browserLogLevel);
            writer.printRaw("\"));");
            writer.println();
            writer.end();
        }

        // module path registration to tapestry javascript sources

        if (_tapestryPath!=null)
        {
            String tapestryUrl = _tapestryPath.buildURL();
            if (tapestryUrl.endsWith("/"))
            {
                tapestryUrl = tapestryUrl.substring(0, tapestryUrl.length() - 1);
            }

            writer.println();
            writer.begin("script");
            writer.attribute("type", "text/javascript");
            writer.println();
            writer.printRaw("dojo.registerModulePath(\"tapestry\", \"");
            writer.printRaw(tapestryUrl);
            writer.printRaw("\");");
            writer.println();
            writer.end();
            writer.println();            
        }

        // include core tapestry.js package

        if (_tapestrySource!=null)
        {
            writer.begin("script");
            writer.attribute("type", "text/javascript");
            writer.attribute("src", _tapestrySource.buildURL());
            writer.end();
        }

        // namespace registration

        writer.println();
        writer.begin("script");
        writer.attribute("type", "text/javascript");
        writer.println();
        writer.printRaw("dojo.require(\"tapestry.namespace\");");
        writer.println();
        writer.printRaw("tapestry.requestEncoding='");
        writer.printRaw(cycle.getEngine().getOutputEncoding());
        writer.printRaw("';");
        writer.println();
        writer.end();

        writer.println();
    }