Implementation of HtmlPage

file: html/schtml/tag/HtmlPage.schtml
<%@
import sc.type.PTypeUtil;

/**
 * This page is the default base for all schtml files with an enclosing html tag that extend this layer.
 * It includes any necessary Javascript files, defines the window id, register the page's URL with the PageDispatcher using the @URL annotation
 * and sets the default lifecycle of the tag object.
 */
// Expose each page with a URL based on their file path, e.g. fileDir/fileName.html
@URL(page=true, subTypesOnly=true)
@sc.obj.ServerTagSettings(jsFiles="js/stags.js")
// Set the lifecycle so we store one instance for each page (or app), for each session
@sc.obj.Scope(name="appSession")
// Init on startup
@MainInit(subTypesOnly=true)
// For the JS runtime, each page by default is deployed in it's own .js file and will include the framework js/tags.js file as a dependency
@sc.js.JSSettings(jsModulePattern="js/<%= typeName %>.js", dependentJSFiles="js/tags.js")
%>
<!DOCTYPE html>
<html abstract="true">
   <head serverContent="true">
      <!-- Setting stateless=true here means that the entire tag and its body are included in the 'outputBody' method of the parent, no object generated for this tag -->
      <script type="text/javascript" stateless="true">
         var sc_windowId = <%= PTypeUtil.getWindowId() %>;
         var sc_appId = "<%= PTypeUtil.getAppId() %>";
         var sc_testMode = <%= PTypeUtil.testMode %>;
      </script>
   </head>
   <body>
   </body>
   <script type="text/javascript" repeat="= JSFiles" src="= repeatVar"></script> 
</html>

The HtmlPage template sets the @URL annotation to indicate that this page object should be assigned a URL (as long as it is not abstract).

The template also defines initial JS variables in the page for windowId and appId and loads any JS files required by this page after the body tag so that they are loaded after the page is rendered.

It sets the @Scope annotation to define the lifecycle of the page (appSession, window, global, etc).

It sets @MainInit so that this page's object instance is created when the app is started.

It sets @JSSettings(jsModulePattern) to specify that all Java code inside of this class goes into a separate .js file.

Because these schtml files turn into StrataCode types, you can modify them or replace them to customize the content for your application without having to change each page. When you want to choose a different base template for a specific page, use extends on that page. If you define your own class, make sure it inherits from the appropriate tag class - e.g. sc.lang.html.HtmlPage for top-level HTML templates, and sc.lang.html.Div for a template which defines a div tag.