org.zkoss.zul
Class Script

java.lang.Object
  extended by org.zkoss.zk.ui.AbstractComponent
      extended by org.zkoss.zul.Script
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Component, Scope, ComponentCtrl, Script

public class Script
extends AbstractComponent
implements Script

A component to represent script codes running at the client. It is the same as HTML SCRIPT tag.

Note: it is the scripting codes running at the client, not at the server. Don't confuse it with the zscript element.

There are three formats when used in a ZUML page:

Method 1: Specify the URL of the JS file

<script type="text/javascript" src="my.js"/>
 

Method 2: Specify the JavaScript codes directly

<script type="text/javascript">
 some_js_at_browser();
</script>
 

Method 3: Specify the JavaScript codes by use of the content property (setContent(java.lang.String)).

<script type="text/javascript">
 <attribute name="content">
  some_js_at_browser();
 </attribute>
</script>
 

Author:
tomyeh
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.zkoss.zk.ui.AbstractComponent
AbstractComponent.Children
 
Field Summary
 
Fields inherited from class org.zkoss.zk.ui.AbstractComponent
_visible
 
Fields inherited from interface org.zkoss.zk.ui.Component
APPLICATION_SCOPE, COMPONENT_SCOPE, DESKTOP_SCOPE, PAGE_SCOPE, REQUEST_SCOPE, SESSION_SCOPE, SPACE_SCOPE
 
Constructor Summary
Script()
           
 
Method Summary
 java.lang.String getCharset()
          Returns the character enconding of the source.
 java.lang.String getContent()
          Returns the content of the script element.
 java.lang.String getSrc()
          Returns the URI of the source that contains the script codes.
 java.lang.String getType()
          Returns the type of this client script.
 boolean isChildable()
          Not childable.
 boolean isDefer()
          Returns whether to defer the execution of the script codes.
 void redraw(java.io.Writer out)
          Redraws this component.
 void setCharset(java.lang.String charset)
          Sets the character encoding of the source.
 void setContent(java.lang.String content)
          Sets the content of the script element.
 void setDefer(boolean defer)
          Sets whether to defer the execution of the script codes.
 void setSrc(java.lang.String src)
          Sets the URI of the source that contains the script codes.
 void setType(java.lang.String type)
          Sets the type of this client script.
 
Methods inherited from class org.zkoss.zk.ui.AbstractComponent
addAnnotation, addAnnotation, addEventHandler, addEventListener, addForward, addForward, addForward, addForward, addMoved, addSharedAnnotationMap, addSharedEventHandlerMap, appendAsapAttr, appendAsapAttr, appendChild, applyProperties, clone, containsVariable, detach, equals, getAnnotatedProperties, getAnnotatedPropertiesBy, getAnnotation, getAnnotation, getAnnotations, getAnnotations, getAttribute, getAttribute, getAttributes, getAttributes, getChildren, getCommand, getDefinition, getDesktop, getEventHandler, getEventHandlerNames, getExtraCtrl, getFellow, getFellowIfAny, getFellows, getFirstChild, getId, getLastChild, getListenerIterator, getMold, getMoldURI, getNamespace, getNextSibling, getPage, getParent, getPreviousSibling, getRoot, getSpaceOwner, getUuid, getVariable, hasFellow, insertBefore, invalidate, isAsapRequired, isInvalidated, isListenerAvailable, isVisible, newChildren, newExtraCtrl, onChildAdded, onChildRemoved, onDrawNewChild, onPageAttached, onPageDetached, onWrongValue, removeAttribute, removeAttribute, removeChild, removeEventListener, removeForward, removeForward, response, sessionDidActivate, sessionWillPassivate, setAttribute, setAttribute, setComponentDefinition, setId, setMold, setPage, setPageBefore, setParent, setVariable, setVisible, smartUpdate, smartUpdate, smartUpdate, smartUpdateDeferred, smartUpdateValues, toString, unsetVariable
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Script

public Script()
Method Detail

getType

public java.lang.String getType()
Returns the type of this client script.

Default: text/javascript.

Specified by:
getType in interface Script

setType

public void setType(java.lang.String type)
Sets the type of this client script. For JavaScript, it is text/javascript

Note: this property is NOT optional. You must specify one.

Specified by:
setType in interface Script

getCharset

public java.lang.String getCharset()
Returns the character enconding of the source. It is used with getSrc().

Default: null.

Specified by:
getCharset in interface Script

setCharset

public void setCharset(java.lang.String charset)
Sets the character encoding of the source. It is used with setSrc(java.lang.String).

Specified by:
setCharset in interface Script

getSrc

public java.lang.String getSrc()
Returns the URI of the source that contains the script codes.

Default: null.

Specified by:
getSrc in interface Script

setSrc

public void setSrc(java.lang.String src)
Sets the URI of the source that contains the script codes.

You either add the script codes directly with the Label children, or set the URI to load the script codes with setSrc(java.lang.String). But, not both.

Specified by:
setSrc in interface Script
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.

Default: false.

Specified by:
isDefer in interface Script

setDefer

public void setDefer(boolean defer)
Sets whether to defer the execution of the script codes.

Specified by:
setDefer in interface Script

getContent

public java.lang.String 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.

Specified by:
getContent in interface Script
Since:
3.0.0

setContent

public void setContent(java.lang.String content)
Sets the content of the script element. By content we mean the JavaScript codes that will be enclosed by the HTML SCRIPT element.

Specified by:
setContent in interface Script
Since:
3.0.0

isChildable

public boolean isChildable()
Not childable.

Specified by:
isChildable in interface Component
Overrides:
isChildable in class AbstractComponent

redraw

public void redraw(java.io.Writer out)
            throws java.io.IOException
Description copied from class: AbstractComponent
Redraws this component. This method implements the mold mechanism.
  1. It first invokes AbstractComponent.getMoldURI() to retrieve the mold to redraw. The mold is either an URI (String) or a ComponentRenderer instance.
  2. If URI, it invokes Execution.include(java.io.Writer, java.lang.String, java.util.Map, int) to generate the output.
  3. If a ComponentRenderer instance, ComponentRenderer.render(org.zkoss.zk.ui.Component, java.io.Writer) is called to generate the output.
  4. Specified by:
    redraw in interface Component
    Overrides:
    redraw in class AbstractComponent
    Throws:
    java.io.IOException


Copyright © 2005-2009 Potix Corporation. All Rights Reserved.