Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.tapestry5.corelib.components
Class Checkbox

    java.lang.Object
      org.apache.tapestry5.corelib.base.AbstractField
          org.apache.tapestry5.corelib.components.Checkbox

All Implemented Interfaces:
  ClientElement, Field

    public class Checkbox

extends AbstractField

A Checkbox component is simply a <input type="checkbox">.

Component Parameters
Name | Description | Type | Flags | Default | Default Prefix | Since
--- | --- | --- | --- | --- | --- | ---
clientId | The id used to generate a page-unique client-side identifier for the component. If a component renders multiple times, a suffix will be appended to the to id to ensure uniqueness. The uniqued value may be accessed via the clientId property. | String |  | prop:componentResources.id | literal |
disabled | If true, then the field will render out with a disabled attribute (to turn off client-side behavior). When the form is submitted, the bound value is evaluated again and, if true, the field's value is ignored (not even validated) and the component's events are not fired. | boolean |  | false | prop |
label | The user presentable label for the field. If not provided, a reasonable label is generated from the component's id, first by looking for a message key named "id-label" (substituting the component's actual id), then by converting the actual id to a presentable string (for example, "userId" to "User Id"). | String |  |  | literal |
value | 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. | boolean | Required |  | prop |

Examples:

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

  ### ViewAccounts.tml

      <html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
          <body>
              <h1>View Accounts</h1>

              <t:form>
                  <t:checkbox t:id="showall" onclick="this.form.submit();"/> <t:label for="showall"/>
              </t:form>

              <t:grid t:id="accounts"/>

          </body>
      </html>

  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 element connected to the checkbox. This is good for accessibility, it also provides a larger "target" to click on. The label's text will be "Show All", derived from the property name. Using a Label component is optional but recommended.

  ### ViewAccounts.java

      public class ViewAccount
      {
          @Property
          @Persist
          private boolean showAll;

          @Inject
          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.

Constructor Summary
`Checkbox()`

Method Summary
`protected void` | `processSubmission(java.lang.String controlName)` Method implemented by subclasses to actually do the work of processing the submission of the form.

Methods inherited from class org.apache.tapestry5.corelib.base.AbstractField
`decorateInsideField, getClientId, getControlName, getLabel, isDisabled, isRequired, putPropertyNameIntoBeanValidationContext, removePropertyNameFromBeanValidationContext, setDecorator, setFormSupport`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### Checkbox

    public Checkbox()

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`
  Parameters:
    `controlName` - the control name of the rendered element (used to find the correct parameter in the request)

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2003-2012 The Apache Software Foundation.