|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Provides the interface for Page controls. Controls are sometimes referred to as components or widgets.
Please noteAbstractControl
provides
a default implementation of the Control interface and allows easy creation
of new controls.
When a Page request event is processed Controls may perform server side event
processing through their onProcess()
method. Controls are generally
rendered in a Page by calling their toString() method.
The Control execution sequence is illustrated below:
getHtmlImports()
method.
For example a custom TextField control specifies that the
custom.js file should be included in the HTML header imports:
public class CustomField extends TextField { protected static final String HTML_IMPORT = "<script type=\"text/javascript\" src=\"{0}/click/custom.js\"></script>\n"; public String getHtmlImports() { String[] args = { getContext().getRequest().getContextPath() }; return MessageFormat.format(HTML_IMPORTS, args); } .. }Please note multiple import lines should be separated by a '\n' char, as the
PageImports
will parse multiple import lines
on the '\n' char and ensure that imports are not included twice.
onDeploy(ServletContext)
method.
Continuing our example the CustomField control deploys its
custom.js file to the /click directory:
public class CustomField extends TextField { .. public void onDeploy(ServletContext servletContext) { ClickUtils.deployFile (servletContext, "/com/mycorp/control/custom.js", "click"); } }Controls using the onDeploy() method must be registered in the application WEB-INF/click.xml for them to be invoked. For example:
<click-app>
<pages package="com.mycorp.page" automapping="true"/>
<controls>
<control classname="com.mycorp.control.CustomField"/>
</controls>
</click-app>
When the Click application starts up it will deploy any control elements
defined in the following files in sequential order:
PageImports
Field Summary | |
static String |
CONTROL_MESSAGES
The global control messages bundle name: click-control. |
Method Summary | |
Context |
getContext()
Deprecated. getContext() is now obsolete on the Control interface, but will still be available on AbstractControl: AbstractControl.getContext() |
String |
getHtmlImports()
Return the HTML import string to be include in the page. |
String |
getId()
Return HTML element identifier attribute "id" value. |
Map |
getMessages()
Return the localized messages Map of the Control. |
String |
getName()
Return the name of the Control. |
Object |
getParent()
Return the parent of the Control. |
void |
onDeploy(ServletContext servletContext)
The on deploy event handler, which provides classes the opportunity to deploy static resources when the Click application is initialized. |
void |
onDestroy()
The on destroy request event handler. |
void |
onInit()
The on initialize event handler. |
boolean |
onProcess()
The on process event handler. |
void |
onRender()
The on render event handler. |
void |
render(HtmlStringBuffer buffer)
Render the control's HTML representation to the specified buffer. |
void |
setListener(Object listener,
String method)
Deprecated. this method is now obsolete on the Control interface, but will still be available on AbstractControl: AbstractControl.setListener(java.lang.Object, java.lang.String) |
void |
setName(String name)
Set the name of the Control. |
void |
setParent(Object parent)
Set the parent of the Control. |
Field Detail |
public static final String CONTROL_MESSAGES
Method Detail |
public Context getContext()
AbstractControl.getContext()
public String getHtmlImports()
protected static final String HTML_IMPORT = "<script type=\"text/javascript\" src=\"{0}/click/custom.js\"></script>"; public String getHtmlImports() { return ClickUtils.createHtmlImport(HTML_IMPORTS, getResourceVersionIndicator(), getContext()); }Note multiple import lines should be separated by a '\n' char, as the
PageImports
will
parse multiple import lines on the '\n' char and ensure that
imports are not included twice.
The order in which JS and CSS files are include will be preserved in the
page.
Also note: a common problem when overriding getHtmlImports in
subclasses is forgetting to call super.getHtmlImports. Consider
carefully whether you should call super.getHtmlImports or not.
public String getId()
AbstractControl.getId()
public void setListener(Object listener, String method)
AbstractControl.setListener(java.lang.Object, java.lang.String)
public boolean onClick() { System.out.println("onClick called"); return true; }
listener
- the listener object with the named method to invokemethod
- the name of the method to invokepublic Map getMessages()
public String getName()
public void setName(String name)
name
- of the control
IllegalArgumentException
- if the name is nullpublic Object getParent()
public void setParent(Object parent)
parent
- the parent of the Controlpublic void onDeploy(ServletContext servletContext)
public void onDeploy(ServletContext servletContext) throws IOException { ClickUtils.deployFile (servletContext, "/com/mycorp/control/custom.js", "click"); }Please note: a common problem when overriding onDeploy in subclasses is forgetting to call super.onDeploy. Consider carefully whether you should call super.onDeploy or not. Click also supports an alternative deployment strategy which relies on packaging resource (stylesheets, JavaScript, images etc.) following a specific convention. See the section Deploying Custom Resources for further details.
servletContext
- the servlet contextpublic void onInit()
onProcess()
method is called.
Container
implementations should recursively
invoke the onInit method on each of their child controls ensuring that
all controls receive this event.
Please note: a common problem when overriding onInit in
subclasses is forgetting to call super.onInit(). Consider
carefully whether you should call super.onInit() or not,
especially for Container
s which by default
call onInit on all their child controls as well.
public boolean onProcess()
Container
implementations should recursively
invoke the onProcess method on each of their child controls ensuring that
all controls receive this event. However when a control onProcess method
return false, no other controls onProcess method should be invoked.
When a control is processed it should return true if the Page should
continue event processing, or false if no other controls should be
processed and the Page.onGet()
or Page.onPost()
methods
should not be invoked.
Please note: a common problem when overriding onProcess in
subclasses is forgetting to call super.onProcess(). Consider
carefully whether you should call super.onProcess() or not,
especially for Container
s which by default
call onProcess on all their child controls as well.
public void onRender()
Container
implementations should recursively
invoke the onRender method on each of their child controls ensuring that
all controls receive this event.
Please note: a common problem when overriding onRender in
subclasses is forgetting to call super.onRender(). Consider
carefully whether you should call super.onRender() or not,
especially for Container
s which by default
call onRender on all their child controls as well.
public void onDestroy()
Container
implementations should recursively
invoke the onDestroy method on each of their child controls ensuring that
all controls receive this event.
Please note: a common problem when overriding onDestroy in
subclasses is forgetting to call super.onDestroy(). Consider
carefully whether you should call super.onDestroy() or not,
especially for Container
s which by default
call onDestroy on all their child controls as well.
public void render(HtmlStringBuffer buffer)
Object.toString()
method should delegate the
rendering to the render method for improved performance.
An example implementation:
public class Border extends AbstractContainer { public String toString() { int estimatedSizeOfControl = 100; HtmlStringBuffer buffer = new HtmlStringBuffer(estimatedSizeOfControl); render(buffer); return buffer.toString(); } /** * @see Control#render(HtmlStringBuffer) */ public void render(HtmlStringBuffer buffer) { buffer.elementStart("div"); buffer.appendAttribute("name", getName()); buffer.closeTag(); buffer.append(getField()); buffer.elementEnd("div"); } }
buffer
- the specified buffer to render the control's output to
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |