org.apache.click.element
Class JsImport

java.lang.Object
  extended by org.apache.click.element.Element
      extended by org.apache.click.element.ResourceElement
          extended by org.apache.click.element.JsImport
All Implemented Interfaces:
Serializable

public class JsImport
extends ResourceElement

Provides a JavaScript HEAD element for importing external JavaScript files using the <script> tag.

Example usage:

 public class MyPage extends Page {

     public List getHeadElements() {
         // We use lazy loading to ensure the JS import is only added the
         // first time this method is called.
         if (headElements == null) {
             // Get the head elements from the super implementation
             headElements = super.getHeadElements();

             JsImport jsImport = new JsImport("/js/js-library.js");
             headElements.add(jsImport);
         }
         return headElements;
     }
 } 
The jsImport instance will be rendered as follows (assuming the context path is myApp):
 <script type="text/javascript" href="/myApp/js/js-library.js"></script> 

See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.apache.click.element.ResourceElement
IF_IE, IF_IE7, IF_LESS_THAN_IE7, IF_LESS_THAN_IE9, IF_LESS_THAN_OR_EQUAL_TO_IE7
 
Constructor Summary
JsImport()
          Constructs a new JavaScript import element.
JsImport(String src)
          Construct a new JavaScript import element with the specified src attribute.
JsImport(String src, boolean useApplicationVersionIndicator)
          Construct a new JavaScript import element with the specified src attribute.
JsImport(String src, String versionIndicator)
          Construct a new JavaScript import element with the specified src attribute and version indicator.
 
Method Summary
 boolean equals(Object o)
           
 String getSrc()
          Return the src attribute.
 String getTag()
          Returns the JavaScript import HTML tag: <script>.
 int hashCode()
           
 boolean isUnique()
          This method always return true because a JavaScript import must be unique based on its src attribute.
 void render(HtmlStringBuffer buffer)
          Render the HTML representation of the JsImport element to the specified buffer.
 void setSrc(String src)
          Sets the src attribute.
 
Methods inherited from class org.apache.click.element.ResourceElement
getConditionalComment, getVersionIndicator, isRenderId, setConditionalComment, setRenderId, setVersionIndicator
 
Methods inherited from class org.apache.click.element.Element
appendAttributes, getAttribute, getAttributes, getContext, getId, hasAttribute, hasAttributes, setAttribute, setId, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JsImport

public JsImport()
Constructs a new JavaScript import element.

The JsImport version indicator will automatically be set to the application version indicator.


JsImport

public JsImport(String src)
Construct a new JavaScript import element with the specified src attribute.

The JsImport version indicator will automatically be set to the application version indicator.

Please note if the given src begins with a "/" character the src will be prefixed with the web application context path.

Parameters:
src - the JavaScript import src attribute

JsImport

public JsImport(String src,
                boolean useApplicationVersionIndicator)
Construct a new JavaScript import element with the specified src attribute.

If useApplicationVersionIndicator is true the version indicator will automatically be set to the application version indicator.

Please note if the given src begins with a "/" character the src will be prefixed with the web application context path.

Parameters:
src - the JavaScript import src attribute
useApplicationVersionIndicator - indicates whether the version indicator will automatically be set to the application version indicator

JsImport

public JsImport(String src,
                String versionIndicator)
Construct a new JavaScript import element with the specified src attribute and version indicator.

Please note if the given src begins with a "/" character the src will be prefixed with the web application context path.

Parameters:
src - the JsImport src attribute
versionIndicator - the version indicator to add to the src path
Method Detail

getTag

public String getTag()
Returns the JavaScript import HTML tag: <script>.

Overrides:
getTag in class Element
Returns:
the JavaScript import HTML tag: <script>

isUnique

public boolean isUnique()
This method always return true because a JavaScript import must be unique based on its src attribute. In other words the Page HEAD should only contain a single JavaScript import for the specific src.

Overrides:
isUnique in class ResourceElement
Returns:
true because JavaScript import must unique based on its src attribute
See Also:
ResourceElement.isUnique()

setSrc

public void setSrc(String src)
Sets the src attribute. If the given src argument is null, the src attribute will be removed.

If the given src begins with a "/" character the src will be prefixed with the web application context path. Note if the given src is already prefixed with the context path, Click won't add it a second time.

Parameters:
src - the new src attribute

getSrc

public String getSrc()
Return the src attribute.

Returns:
the src attribute

render

public void render(HtmlStringBuffer buffer)
Render the HTML representation of the JsImport element to the specified buffer.

Overrides:
render in class ResourceElement
Parameters:
buffer - the buffer to render output to

equals

public boolean equals(Object o)
Overrides:
equals in class Object
Parameters:
o - the object with which to compare this instance with
Returns:
true if the specified object is the same as this object
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
Overrides:
hashCode in class Object
Returns:
a hash code value for this object
See Also:
Object.hashCode()