Class Checkbox

  • All Implemented Interfaces:
    ClientElement, Field

    public class Checkbox
    extends AbstractField
    A Checkbox component is simply a <input type="checkbox">.
    Component Parameters 
    NameTypeFlagsDefaultDefault Prefix
    clientIdString  literal
    Used to explicitly set the client-side id of the element for this component. Normally this is not bound (or null) and is used to generate a unique client-id based on the component's id. In some cases, when creating client-side behaviors, it is useful to explicitly set a unique id for an element using this parameter. Certain values, such as "submit", "method", "reset", etc., will cause client-side conflicts and are not allowed; using such will cause a runtime exception.
    ensureClientIdUniquebooleanSince 5.4 prop
    A rarely used option that indicates that the actual client id should start with the clientId parameter (if non-null) but should still pass that Id through to generate the final id. An example of this are the components used inside a org.apache.tapestry5.corelib.components.BeanEditor which will specify a clientId (based on the property name) but still require that it be unique. Defaults to false.
    validateorg.apache.tapestry5.FieldValidatorNot Null validate
    The object that will perform input validation. The validate binding prefix is generally used to provide this object in a declarative fashion.
    valuebooleanRequired prop
    The value to be read or updated. If not bound, the Checkbox will attempt to edit a property of its container whose name matches the component's id.


    In this example, a Checkbox will be used alone to manipulate a property of the page.


    <html xmlns:t="">
            <h1>View Accounts</h1>
                <t:checkbox t:id="showall" onclick="this.form.submit();"/> <t:label for="showall"/>
            <t:grid t:id="accounts"/>

    The Grid component will do most of the work in terms of displaying the account data.

    Normally, we should bind the value parameter explicitly; here the component's id, "showAll", matches against a property of the page and the value parameter is automatically bound as a convenience.

    A small amount of JavaScript is provided in-line to submit the form when the checkbox is clicked.

    All Tapestry form control element components must be enclosed by a Form component.

    The Label component is responsible for rendering a

    public class ViewAccount
        private boolean showAll;
        private AccountDAO accountDAO;
        public List<Account> getAccounts()
            return showAll ? accountDAO.getAllAccounts() : accountDAO.getActiveAccounts();

    The component updates the showAll field, and that's used to determine which set of accounts should be provided to the Grid component. As always in Tapestry, you must be careful to mark fields persistent if they need to hold their value between the action request (the form submission) and the render request.

    • Method Detail

      • processSubmission

        protected void processSubmission​(java.lang.String controlName)
        Description copied from class: AbstractField
        Method implemented by subclasses to actually do the work of processing the submission of the form. The element's controlName property will already have been set. This method is only invoked if the field is not disabled.
        Specified by:
        processSubmission in class AbstractField
        controlName - the control name of the rendered element (used to find the correct parameter in the request)