Class Script
- All Implemented Interfaces:
Serializable,Cloneable,org.zkoss.zk.ui.Component,org.zkoss.zk.ui.ext.Scope,org.zkoss.zk.ui.sys.ComponentCtrl
setDefer(boolean))
will cause the evaluation of JavaScript until the widget has been
instantiated and mounted to the DOM tree.
Note: it is the script codes running at the client, not at the
server. Don't confuse it with the zscript element.
There are several way to embed script codes in a ZUML page:
Approach 1: Specify the URL of the JS file without defer. The JavaScript codes are evaluated as soon as the file is loaded.
<script src="my.js"/>
Approach 2: Specify the JavaScript codes directly without defer. The JavaScript codes are evaluated immediately before the widget is instantiated, so you cannot access any widget. Rather, it is used to do desktop-level initialization, such as defining a widget class, and a global function.
<script defer="true">
zk.$package('foo');
zk.load('zul.wgt', function () {
foo.Foo = zk.$extends(zul.Widget, {
//...
</script>
Approach 3: Specify the JavaScript codes directly with defer.
The JavaScipt codes are evaluated after the widget is instantiated and
mounted. Moreover, this references to the script widget,
so you can access the widgets as follows.
<script defer="true">
this.getFellow('l').setValue('new value');
//...
</script>
Alternative to Script, you can use the script directive
as shown below..
<?script src="/js/mine.js"?/>
<?script content="jq.IE6_ALPHAFIX=/.png/"?/>
- Author:
- tomyeh
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.zkoss.zk.ui.AbstractComponent
org.zkoss.zk.ui.AbstractComponent.Children, org.zkoss.zk.ui.AbstractComponent.ForwardInfo, org.zkoss.zk.ui.AbstractComponent.TargetInfo -
Field Summary
Fields inherited from interface org.zkoss.zk.ui.Component
APPLICATION_SCOPE, COMPONENT_SCOPE, DESKTOP_SCOPE, PAGE_SCOPE, REQUEST_SCOPE, SESSION_SCOPE, SPACE_SCOPEFields inherited from interface org.zkoss.zk.ui.sys.ComponentCtrl
AFTER_CHILD_ADDED, AFTER_CHILD_REMOVED, AFTER_CLONED, AFTER_PAGE_ATTACHED, AFTER_PAGE_DETACHED, AFTER_PARENT_CHANGED, CE_BUSY_IGNORE, CE_DUPLICATE_IGNORE, CE_IMPORTANT, CE_NON_DEFERRABLE, CE_REPEAT_IGNORE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the character encoding of the source.Returns the content of the script element.Returns the list of packages to load before evaluating the script defined ingetContent().getSrc()Returns the URI of the source that contains the script codes.protected booleanNot childable.booleanisDefer()Returns whether to defer the execution of the script codes until the widget is instantiated and mounted.protected voidrenderProperties(org.zkoss.zk.ui.sys.ContentRenderer renderer) voidsetCharset(String charset) Sets the character encoding of the source.voidsetContent(String content) Sets the content of the script element.voidsetDefer(boolean defer) Sets whether to defer the execution of the script codes.voidsetPackages(String packages) Sets the list of packages to load before evaluating the script defined ingetContent().voidSets the URI of the source that contains the script codes.Methods inherited from class org.zkoss.zk.ui.AbstractComponent
addAnnotation, addCallback, addClientEvent, addEventHandler, addEventListener, addEventListener, addForward, addForward, addForward, addForward, addMoved, addRedrawCallback, addScopeListener, addShadowRoot, addShadowRootBefore, addSharedEventHandlerMap, appendChild, applyProperties, beforeChildAdded, beforeChildRemoved, beforeParentChanged, clone, destroyIndexCacheMap, detach, didActivate, didActivate, didDeserialize, didDeserialize, disableBindingAnnotation, disableClientUpdate, disableHostChanged, enableBindingAnnotation, enableHostChanged, getAnnotatedProperties, getAnnotatedPropertiesBy, getAnnotation, getAnnotations, getAnnotations, getAttribute, getAttribute, getAttribute, getAttributeOrFellow, getAttributes, getAttributes, getAuService, getAutag, getCallback, getChildren, getClientAttribute, getClientDataAttribute, getClientEvents, getDefaultMold, getDefinition, getDesktop, getEventHandler, getEventHandlerNames, getEventListenerMap, getEventListeners, getExtraCtrl, getFellow, getFellow, getFellowIfAny, getFellowIfAny, getFellows, getFirstChild, getForwards, getId, getIndexCacheMap, getLastChild, getMold, getNextSibling, getPage, getParent, getPreviousSibling, getPropertyAccess, getRedrawCallback, getRoot, getShadowFellowIfAny, getShadowRoots, getShadowVariable, getShadowVariable, getShadowVariable0, getSpaceOwner, getSpecialRendererOutput, getStubonly, getStubonlyDescendants, getSubBindingAnnotationCount, getTemplate, getTemplateNames, getUuid, getWidgetAttributeNames, getWidgetClass, getWidgetListener, getWidgetListenerNames, getWidgetOverride, getWidgetOverrideNames, hasAttribute, hasAttribute, hasAttribute, hasAttributeOrFellow, hasBindingAnnotation, hasFellow, hasFellow, hasSubBindingAnnotation, initIndexCacheMap, insertBefore, invalidate, isDisabledHostChanged, isInitialized, isInvalidated, isListenerAvailable, isVisible, onChildAdded, onChildRemoved, onPageAttached, onPageDetached, onParentChanged, onWrongValue, query, queryAll, redraw, redrawChildren, removeAttribute, removeAttribute, removeAttribute, removeCallback, removeChild, removeEventListener, removeForward, removeForward, removeRedrawCallback, removeScopeListener, removeShadowRoot, render, render, render, renderPropertiesOnly, replace, response, response, response, service, service, sessionDidActivate, sessionWillPassivate, setAttribute, setAttribute, setAttribute, setAuService, setAutag, setClientAttribute, setClientDataAttribute, setDefinition, setDefinition, setId, setMold, setPage, setPageBefore, setParent, setStubonly, setStubonly, setStubonlyDescendants, setSubBindingAnnotationCount, setTemplate, setVisible, setVisibleDirectly, setWidgetClass, setWidgetListener, setWidgetOverride, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdateWidgetListener, smartUpdateWidgetOverride, toString, updateByClient, updateSubBindingAnnotationCount, willPassivate, willPassivate, willSerialize, willSerialize
-
Constructor Details
-
Script
public Script() -
Script
Constructs a script component with the specified content.- Parameters:
content- the content (the code snippet).- Since:
- 6.0.0
-
-
Method Details
-
getCharset
Returns the character encoding of the source. It is used withgetSrc().Default: null.
-
setCharset
Sets the character encoding of the source. It is used withsetSrc(java.lang.String).Refer to HTML Character Setsfor more information.
-
getSrc
Returns the URI of the source that contains the script codes.Default: null.
-
setSrc
Sets the URI of the source that contains the script codes.You either add the script codes directly with the
Labelchildren, or set the URI to load the script codes withsetSrc(java.lang.String). But, not both.- Parameters:
src- the URI of the source that contains the script codes
-
isDefer
public boolean isDefer()Returns whether to defer the execution of the script codes until the widget is instantiated and mounted.Default: false.
Specifying false (default), if you want to do the desktop-level (or class-level) initialization, such as defining a widget class or a global function.
Specifying true, if you want to access widgets. Notice that
thisreferences to this script widget. -
setDefer
public void setDefer(boolean defer) Sets whether to defer the execution of the script codes.- See Also:
-
getContent
Returns the content of the script element. By content we mean the JavaScript codes that will be enclosed by the HTML SCRIPT element.Default: null.
Deriving class can override this method to return whatever it prefers (ignored if null).
- Since:
- 3.0.0
-
setContent
Sets the content of the script element. By content we mean the JavaScript codes that will be enclosed by the HTML SCRIPT element.- Since:
- 3.0.0
-
getPackages
Returns the list of packages to load before evaluating the script defined ingetContent(). It is meaning only ifgetContent()not null.Default: null.
- Since:
- 5.0.0
-
setPackages
Sets the list of packages to load before evaluating the script defined ingetContent(). If more than a package to load, separate them with comma.- Since:
- 5.0.0
-
renderProperties
- Overrides:
renderPropertiesin classorg.zkoss.zk.ui.AbstractComponent- Throws:
IOException
-
isChildable
protected boolean isChildable()Not childable.- Overrides:
isChildablein classorg.zkoss.zk.ui.AbstractComponent
-