org.olat.core.gui.components.htmlheader.jscss
Class JSAndCSSComponent

java.lang.Object
  extended by org.olat.core.gui.components.Component
      extended by org.olat.core.gui.components.htmlheader.jscss.JSAndCSSComponent

public class JSAndCSSComponent
extends Component

Description:
a fake component which only serves to request additional .js or .css files for a controller/component. In order to activate it, this component here must be inserted into the rendertree, e.g. myVelocityContainer.put("jsAndCss", myJsAndCssComponent);

Initial Date: 03.05.2006

Author:
Felix Jost

Constructor Summary
JSAndCSSComponent(java.lang.String componentName, java.lang.Class baseClass, java.lang.String[] jsFileNames, java.lang.String cssFileName, boolean forceCssRemove)
           
JSAndCSSComponent(java.lang.String componentName, java.lang.Class baseClass, java.lang.String[] jsFileNames, java.lang.String cssFileName, boolean forceCssRemove, java.lang.String rawHeader)
           
JSAndCSSComponent(java.lang.String componentName, java.lang.Class baseClass, java.lang.String[] jsFileNames, java.lang.String cssFileName, boolean forceCssRemove, java.lang.String rawHeader, int refreshIntervall)
           
 
Method Summary
 void addAutoRemovedCssPathName(java.lang.String cssPathName, int cssLoadIndex)
          used rather rarely, e.g.
 ComponentRenderer getHTMLRendererSingleton()
           
 void requireFullPageRefresh()
          requires that a full page reload takes places.
 void setRefreshIntervall(int refreshIntervall)
           
 void validate(UserRequest ureq, ValidationResult vr)
          called just before the rendering of the -whole tree- takes place, so e.g.
 
Methods inherited from class org.olat.core.gui.components.Component
addListener, debuginfoGetListeners, dispatchRequest, getAndClearLatestFiredEvent, getComponentName, getDispatchID, getExtendedDebugInfo, getLatestDispatchedController, getListenerInfo, getParent, getSpanAsDomReplaceable, getTimestamp, getTranslator, isDirty, isDirtyForUser, isDomReplaceable, isEnabled, isVisible, setDirty, setDomReplaceable, setEnabled, setSpanAsDomReplaceable, setVisible, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JSAndCSSComponent

public JSAndCSSComponent(java.lang.String componentName,
                         java.lang.Class baseClass,
                         java.lang.String[] jsFileNames,
                         java.lang.String cssFileName,
                         boolean forceCssRemove,
                         java.lang.String rawHeader,
                         int refreshIntervall)
Parameters:
componentName - the name of the component
baseClass - the class of the controller (or from the package's Manager) from where the resources will be fetched: e.g. org/olat/demo/_static/js or /css respectively.
jsFileNames - maybe null An array of the jsFilenames, one entry is e.g. "script.js", which will then be resolved to baseClass/_static/js/script.js
cssFileName - maybe null the name of the cssFile to include: e.g. "style.css" will be resolved to loc of baseClass/_static/css/style.css
forceCssRemove - if true, the given css will be removed if no longer necessary (e.g. for a custom css as in the course), otherwise it will stay in the html-header for the whole usersession
rawHeader - -only use if neither jsFileNames nor cssFileName can be used (only for dynamically created jslibs for example)-a string (e.g. "refreshIntervall - the time in miliseconds after which (in ajax mode) a refresh of the screen is needed. -1 means infinity/no refresh. use small times with caution, since it generates server load. after the given time, a poll (comet, push, hanging get for future release) is issued to the server to collect the dirty components and rerender them. when more than one interval is requested, then the minimum is taken.

JSAndCSSComponent

public JSAndCSSComponent(java.lang.String componentName,
                         java.lang.Class baseClass,
                         java.lang.String[] jsFileNames,
                         java.lang.String cssFileName,
                         boolean forceCssRemove,
                         java.lang.String rawHeader)
Parameters:
componentName - the name of the component
baseClass - the class of the controller (or from the package's Manager) from where the resources will be fetched: e.g. org/olat/demo/_static/js or /css respectively.
jsFileNames - maybe null An array of the jsFilenames, one entry is e.g. "script.js", which will then be resolved to baseClass/_static/js/script.js
cssFileName - maybe null the name of the cssFile to include: e.g. "style.css" will be resolved to loc of baseClass/_static/css/style.css
forceCssRemove - if true, the given css will be removed if no longer necessary (e.g. for a custom css as in the course), otherwise it will stay in the html-header for the whole usersession
rawHeader - -only use if neither jsFileNames nor cssFileName can be used (only for dynamically created jslibs for example)-a string (e.g. "

JSAndCSSComponent

public JSAndCSSComponent(java.lang.String componentName,
                         java.lang.Class baseClass,
                         java.lang.String[] jsFileNames,
                         java.lang.String cssFileName,
                         boolean forceCssRemove)
Parameters:
componentName - the name of the component
baseClass - the class of the controller (or from the package's Manager) from where the resources will be fetched: e.g. org/olat/demo/_static/js or /css respectively.
jsFileNames - maybe null An array of the jsFilenames, one entry is e.g. "script.js", which will then be resolved to baseClass/_static/js/script.js
cssFileName - maybe null the name of the cssFile to include: e.g. "style.css" will be resolved to loc of baseClass/_static/css/style.css
forceCssRemove - if true, the given css will be removed if no longer necessary (e.g. for a custom css as in the course), otherwise it will stay in the html-header for the whole usersession
Method Detail

validate

public void validate(UserRequest ureq,
                     ValidationResult vr)
Description copied from class: Component
called just before the rendering of the -whole tree- takes place, so e.g. lazy fetching can be implemented, or issueing a request for a new moduleUri (e.g. for CPComponent, so that the browser loads images correctly). only called when the component is visible

Overrides:
validate in class Component

getHTMLRendererSingleton

public ComponentRenderer getHTMLRendererSingleton()
Specified by:
getHTMLRendererSingleton in class Component

addAutoRemovedCssPathName

public void addAutoRemovedCssPathName(java.lang.String cssPathName,
                                      int cssLoadIndex)
used rather rarely, e.g. when you have a css with content which is dynamic (e.g. a custom course css in olat).
Use a Mapper/MapperRegistry to obtain a cssPath. The css is assumed to be flagged with autoremove, that is, it is removed as soon as no one requires it in the validation phase (since those special css are created by a mapper which in turn is created by a controller so that it makes sense to limit the css lifespan to the lifespan of the controller)
Normally use the cssFileName parameter in the constructor for class-based static css files.

Parameters:
cssPathName - the path to the css, e.g. /olat/m/1001/mycss.css
cssLoadIndex - flag to indicate load order of this CSS. See JSAndCSSAdder.CSS_INDEX_*
See Also:
JsAndCssAdder.addRequiredCSSPath(String cssPath, boolean forceRemove);

setRefreshIntervall

public void setRefreshIntervall(int refreshIntervall)
Parameters:
refreshIntervall - - refresh intervall in ms, -1 no more polling i.e. <=1000 no more polling according to /olatcore/org/olat/core/gui/control/winmgr/_content/serverpart.html

requireFullPageRefresh

public void requireFullPageRefresh()
requires that a full page reload takes places. sometimes eval'ing a more complex js lib (such as tiny mce) directly into global context does not work (timing issues?) this should be used only rarely when complex js is executed and has errors in it, since a full page refresh is slower than a ajax call.
when this component is validated (last cycle before rendering), and a full page refresh is required, then a full page request command is sent via JSON to the browser which then executes it using document.location.replace(...). Since this step involves two calls (JSON+reload), this is slower than a normal full page click (aka known as non-ajax mode).