Class ViewLoader

All Implemented Interfaces:
HasAttachHandlers, HasHandlers, EventListener, HasVisibility, IsWidget, LogicalStructure, HasClearHandlers, HasClickHandlers, HasDoubleClickHandlers, HasDragMoveHandlers, HasDragRepositionMoveHandlers, HasDragRepositionStartHandlers, HasDragRepositionStopHandlers, HasDragResizeMoveHandlers, HasDragResizeStartHandlers, HasDragResizeStopHandlers, HasDragStartHandlers, HasDragStopHandlers, HasDropHandlers, HasDropMoveHandlers, HasDropOutHandlers, HasDropOverHandlers, HasFocusChangedHandlers, HasHoverHandlers, HasHoverHiddenHandlers, HasIconClickHandlers, HasKeyDownHandlers, HasKeyPressHandlers, HasMouseDownHandlers, HasMouseMoveHandlers, HasMouseOutHandlers, HasMouseOverHandlers, HasMouseStillDownHandlers, HasMouseUpHandlers, HasMouseWheelHandlers, HasMovedHandlers, HasParentMovedHandlers, HasResizedHandlers, HasRightMouseDownHandlers, HasRuleContextChangedHandlers, HasScrolledHandlers, HasShowContextMenuHandlers, HasTitleHoverHandlers, HasVisibilityChangedHandlers

public class ViewLoader extends Label
The ViewLoader component can be used to load new Smart GWT-based user interfaces into a running application.

NOTE: before using a ViewLoader, be sure that you have read about and understood the Smart GWT Architecture. The most responsive and scalable application architecture preloads views rather than using ViewLoaders.

A ViewLoader is a Canvas, and can be provided anywhere a Canvas can be provided: as a Tab pane, and Layout member, etc. When a ViewLoader draws, it shows a loading message, then performs an RPC to the viewURL to load components.

The response from the viewURL should be Smart GWT components defined in JavaScript, with no surrounding <SCRIPT> tags or other HTML framing. The returned script can be dynamically generated, for example, it may be the result of a JSP containing an XML view description enclosed in <isomorphicXML> tags.

In the returned script, the special variable "viewLoader" is available to refer to the ViewLoader instance that is loading components. The intended usage is that the returned script creates a view consisting of Smart GWT components, then calls viewLoader.setView(myView) to place the loaded view into the ViewLoader. If the view does not call setView() explicitly, the viewLoader will find the last top-level UI component (Canvas subclass) created by the view and set that as the current view. Top-level in this case means that the UI component is not contained in another UI component as a member or child.

The ViewLoader relies on the XMLHttpRequest object which can be disabled by end-users in some supported browsers. See PlatformDependencies for more information.

See Also:
  • Constructor Details

    • ViewLoader

      public ViewLoader()
    • ViewLoader

      public ViewLoader(JavaScriptObject jsObj)
  • Method Details

    • getOrCreateRef

      public static ViewLoader getOrCreateRef(JavaScriptObject jsObj)
    • changeAutoChildDefaults

      public static void changeAutoChildDefaults(String autoChildName, Canvas defaults)
      Changes the defaults for Canvas AutoChildren named autoChildName.
      Parameters:
      autoChildName - name of an AutoChild to customize the defaults for.
      defaults - Canvas defaults to apply. These defaults override any existing properties without destroying or wiping out non-overridden properties. For usage tips on this param, see SGWTProperties.
      See Also:
    • changeAutoChildDefaults

      public static void changeAutoChildDefaults(String autoChildName, FormItem defaults)
      Changes the defaults for FormItem AutoChildren named autoChildName.
      Parameters:
      autoChildName - name of an AutoChild to customize the defaults for.
      defaults - FormItem defaults to apply. These defaults override any existing properties without destroying or wiping out non-overridden properties. For usage tips on this param, see SGWTProperties.
      See Also:
    • create

      protected JavaScriptObject create()
      Overrides:
      create in class Label
    • setAllowCaching

      public ViewLoader setAllowCaching(Boolean allowCaching) throws IllegalStateException
      By default a ViewLoader will explicitly prevent browser caching.

      Set to true to allow browser caching if the browser would normally do so, in other words, if the HTTP headers returned with the response indicate that the response can be cached.

      Parameters:
      allowCaching - New allowCaching value. Default value is false
      Returns:
      ViewLoader instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the component has been created
    • getAllowCaching

      public Boolean getAllowCaching()
      By default a ViewLoader will explicitly prevent browser caching.

      Set to true to allow browser caching if the browser would normally do so, in other words, if the HTTP headers returned with the response indicate that the response can be cached.

      Returns:
      Current allowCaching value. Default value is false
    • setHttpMethod

      public ViewLoader setHttpMethod(String httpMethod)
      Selects the HTTP method that will be used when fetching content. Valid values are "POST" and "GET".
      Parameters:
      httpMethod - New httpMethod value. Default value is "GET"
      Returns:
      ViewLoader instance, for chaining setter calls
    • getHttpMethod

      public String getHttpMethod()
      Selects the HTTP method that will be used when fetching content. Valid values are "POST" and "GET".
      Returns:
      Current httpMethod value. Default value is "GET"
    • setLoadingMessage

      public ViewLoader setLoadingMessage(String loadingMessage) throws IllegalStateException
      Message to show while the view is loading. Use "${loadingImage}" to include a loading image.
      Parameters:
      loadingMessage - New loadingMessage value. Default value is "Loading View...&nbsp;${loadingImage}"
      Returns:
      ViewLoader instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the component has been created
      See Also:
    • getLoadingMessage

      public String getLoadingMessage()
      Message to show while the view is loading. Use "${loadingImage}" to include a loading image.
      Returns:
      Current loadingMessage value. Default value is "Loading View...&nbsp;${loadingImage}"
      See Also:
    • setViewURL

      public ViewLoader setViewURL(String viewURL) throws IllegalStateException
      URL to load components from.

      If this method is called after the component has been drawn/initialized: Change the URL this component loads a view from. Triggers a fetch from the new URL.

      Can also be called with no arguments to reload the view from the existing viewURL.

      Parameters:
      viewURL - URL to retrieve view from. Default value is null
      Returns:
      ViewLoader instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the component has been created
      See Also:
    • getViewURL

      public String getViewURL()
      URL to load components from.
      Returns:
      Current viewURL value. Default value is null
      See Also:
    • getView

      public Canvas getView()
      Retrieve the current view. May be null if the view has not yet been loaded, or has been explicitly set to null.
      Returns:
      the current view
    • viewLoaded

      public void viewLoaded(Canvas view)
      StringMethod fired when the view has been loaded. Has no default implementation. Add a notification to fire custom logic when loading completes.
      Parameters:
      view - the view that was loaded
    • setDefaultProperties

      public static void setDefaultProperties(ViewLoader viewLoaderProperties)
      Class level method to set the default properties of this class. If set, then all existing and subsequently created instances of this class will automatically have default properties corresponding to the properties set on the SmartGWT class instance passed to this function before its underlying SmartClient JS object was created. This is a powerful feature that eliminates the need for users to create a separate hierarchy of subclasses that only alter the default properties of this class. Can also be used for skinning / styling purposes.

      Note: This method is intended for setting default attributes only and will affect all instances of the underlying class (including those automatically generated in JavaScript). This method should not be used to apply standard EventHandlers or override methods for a class - use a custom subclass instead. Calling this method after instances have been created can result in undefined behavior, since it bypasses any setters and a class instance may have already examined a particular property and not be expecting any changes through this route.

      Parameters:
      viewLoaderProperties - properties that should be used as new defaults when instances of this class are created
      See Also:
    • setLogicalStructure

      public LogicalStructureObject setLogicalStructure(ViewLoaderLogicalStructure s)
      Setter implementing the LogicalStructure interface, which supports Eclipse's logical structure debugging facility.
    • getLogicalStructure

      public LogicalStructureObject getLogicalStructure()
      Getter implementing the LogicalStructure interface, which supports Eclipse's logical structure debugging facility.
      Specified by:
      getLogicalStructure in interface LogicalStructure
      Overrides:
      getLogicalStructure in class Label