Provides the interface for Page controls. Controls are also referred to as components or widgets.
When a Page request event is processed Controls may perform server side event processing through their {@link #onProcess()} method. Controls are generallyrendered in a Page by calling their
toString() method.
The Control execution sequence is illustrated below:
HTML Header Imports
Control HTML header imports can be exposed by overriding the {@link #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 {@link org.apache.click.util.PageImports} will parse multiple import lineson the
'\n' char and ensure that imports are not included twice.
Deploying Resources
The Click framework uses the Velocity Tools
WebappLoader for loading templates. This avoids issues associate with using the Velocity
ClasspathResourceLoader and
FileResourceLoader on J2EE application servers. To make preconfigured resources (templates, stylesheets, etc.) available to web applications Click automatically deploys configured classpath resources to the
/click directory at startup (existing files will not be overwritten).
To enable Controls to deploy static resources on startup this interface provides an {@link #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:
- /click-controls.xml
- /extras-controls.xml
- WEB-INF/click.xml
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.
Please note {@link org.apache.click.control.AbstractControl} providesa default implementation of the Control interface to make it easier for developers to create their own controls.
@see org.apache.click.util.PageImports