|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.click.element.Element org.apache.click.element.ResourceElement
public class ResourceElement
Provides a base class for rendering HEAD resources of an HTML page, for example JavaScript (<script>) and Cascading Stylesheets (<link>/<style>).
Subclasses should overrideElement.getTag()
to return a specific HTML tag.
Below are some example Resource elements:
JsImport
, for importing external JavaScript using the
<script> element.JsScript
, for including inline JavaScript using the
<script> element.CssImport
, for importing external Cascading Stylesheets
using the <link> element.CssStyle
, for including inline Cascading Stylesheets
using the <style> element.isUnique()
property. Thus if the same Resource is imported
multiple times by the Page or different Controls, only one Resource will be
rendered, if isUnique()
returns true.
The rules for defining a unique Resource is as follows:
JsImport
and CssImport
is unique based on the
attributes JsImport.getSrc()
and CssImport.getHref()
respectively.JsScript
and CssStyle
is unique if their HTML
ID
attribute is set. The HTML
spec defines that an element's HTML ID must be unique per page.public class MyPage extends Page { public List getHeadElements() { // We use lazy loading to ensure the JavaScript and Css 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/mylib.js"); // Click will ensure the library "/js/mylib.js" is only included // once in the Page headElements.add(jsImport); JsScript jsScript = new JsScript("alert('Hello!');"); // Click won't ensure the script is unique because its ID // attribute is not defined headElements.add(jsScript); jsScript = new JsScript("alert('Hello!');"); jsScript.setId("my-unique-script-id"); // Click will ensure the script is unique because its ID attribute // is defined. Click will remove other scripts with the same ID headElements.add(jsScript); CssImport cssImport = new CssImport("/css/style.css"); // Click will ensure the library "/css/style.css" is only // included once in the Page headElements.add(cssImport); CssScript cssScript = new CssScript("body { font-weight: bold; }"); cssScript.setId("my-unique-style-id"); // Click will ensure the css is unique because its ID attribute // is defined. Click will remove other css styles with the same ID headElements.add(cssScript); } return headElements; } }
ClickUtils.ENABLE_RESOURCE_VERSION
request attribute must be set to trueapplication version
must be setpublic class MyPage extends Page { public List getHeadElements() { // We use lazy loading to ensure the JavaScript and Css is only added // the first time this method is called. if (headElements == null) { // Get the head elements from the super implementation headElements = super.getHeadElements(); CssImport cssImport = new CssImport("/css/ie-style.css"); // Use one of the predefined conditional comments to target IE6 // and below cssImport.setConditionalComment(IE_LESS_THAN_IE7); headElements.add(cssImport); cssImport = new CssImport("/css/ie-style2.css"); // Use a custom predefined conditional comments to target only IE6 cssImport.setConditionalComment("[if IE 6]"); headElements.add(cssImport); } return headElements; } }ResourceElement contains some predefined Conditional Comments namely
IF_IE
, IF_LESS_THAN_IE7
and IF_IE7
.
Field Summary | |
---|---|
static String |
IF_IE
A predefined conditional comment to test if browser is IE. |
static String |
IF_IE7
A predefined conditional comment to test if browser is IE7. |
static String |
IF_LESS_THAN_IE7
A predefined conditional comment to test if browser is less than IE7. |
static String |
IF_LESS_THAN_IE9
A predefined conditional comment to test if browser is less than IE9. |
static String |
IF_LESS_THAN_OR_EQUAL_TO_IE7
A predefined conditional comment to test if browser is less than or equal to IE7. |
Constructor Summary | |
---|---|
ResourceElement()
|
Method Summary | |
---|---|
String |
getConditionalComment()
Return Internal Explorer's conditional comment to wrap the Resource with. |
String |
getVersionIndicator()
Return the version indicator to be appended to the resource path. |
boolean |
isRenderId()
Returns the element render ID attribute status, default
value is true. |
boolean |
isUnique()
Returns whether or not the Resource unique. |
void |
render(HtmlStringBuffer buffer)
Render the HTML representation of the Resource element to the specified buffer. |
void |
setConditionalComment(String conditionalComment)
Set Internet Explorer's conditional comment to wrap the Resource with. |
void |
setRenderId(boolean renderId)
Set the element render ID attribute status. |
void |
setVersionIndicator(String versionIndicator)
Set the version indicator to be appended to the resource path. |
Methods inherited from class org.apache.click.element.Element |
---|
appendAttributes, getAttribute, getAttributes, getContext, getId, getTag, hasAttribute, hasAttributes, setAttribute, setId, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String IF_IE
public static final String IF_LESS_THAN_IE7
public static final String IF_IE7
public static final String IF_LESS_THAN_OR_EQUAL_TO_IE7
public static final String IF_LESS_THAN_IE9
Constructor Detail |
---|
public ResourceElement()
Method Detail |
---|
public String getVersionIndicator()
public void setVersionIndicator(String versionIndicator)
versionIndicator
- the version indicator to be appended to the
resource pathpublic boolean isUnique()
ID
attribute is defined,
false otherwise.
public boolean isRenderId()
ID
attribute status, default
value is true.
setRenderId(boolean)
public void setRenderId(boolean renderId)
ID
attribute status.
If renderId is false the element ID
attribute will not
be rendered.
renderId
- set the element render id attribute statuspublic String getConditionalComment()
public void setConditionalComment(String conditionalComment)
conditionalComment
- Internet Explorer's conditional comment to wrap
the Resource withpublic void render(HtmlStringBuffer buffer)
Element.getTag()
returns null, this method will return an empty
string.
render
in class Element
buffer
- the specified buffer to render the Resource element output
to
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |