<netui:checkBoxGroup> Tag

Handles data binding for a collection of checkboxes.

Syntax

<netui:checkBoxGroup
    dataSource="dataSource"
    [defaultValue="defaultValue"]
    [disabled="disabled"]
    [labelStyle="labelStyle"]
    [labelStyleClass="labelStyleClass"]
    [optionsDataSource="optionsDataSource"]
    [orientation="orientation"]
    [repeater="repeater"]
    [style="style"]
    [styleClass="styleClass"] />

Description

Handles data binding for a collection of checkboxes.

Submitting Data

The <netui:checkBoxGroup> submits data in the form of a String[] object. For example, if the <netui:checkBoxGroup> submits data to a Form Bean field...

        <netui:checkBoxGroup
                  dataSource="{actionForm.userSelections}"
                  optionsDataSource="{pageFlow.availableSelections}" />
...then the Form Bean field must be a String[] object...
      public static class SubmitForm extends FormData
      {
          private String[] userSelections;

          public void setUserSelections(String[] userSelections)
          {
              this.userSelections = userSelections;
          }

          public String[] getUserSelections()
          {
              return this.userSelections;
          }
      }

Dynamically Defined Checkboxes

You can dynamically define a set of checkboxes by pointing the optionsDataSource attribute at a String[] object. When the <netui:checkBoxGroup> is rendered in the browser, a corresponding set of checkboxes will be genereated from the String[] object.

For example, if you define a String[] object in the Controller file...

    public String[] availableOptions = {"option1", "option2", "option3"};
...and reference this String[] from the optionDataSource attribute...
        <netui:checkBoxGroup
                  dataSource="{actionForm.userSelections}"
                  optionsDataSource="{pageFlow.availableSelections}" />
...then the appropriate checkboxes will be rendered in the browser.
      <input type="checkbox" value="option1">option1</input>
      <input type="checkbox" value="option2">option2</input>
      <input type="checkbox" value="option3">option3</input>
For checkboxes to be rendered, either the optionsDataSource attribute must be provided (and point to a String[] object) or the <netui:checkBoxGroup> must have children <netuiCheckBoxOption> tags.

Setting Default Options

The defaultValue attribute can be used to determine which checkboxs are checked when they are first rendered in the browser. The defaultValue attribute should point to a String, if only one checkbox should appear checked, or to a String[] object, if multiple checkboxes should appear checked.

Attributes
dataSource
Required: Yes  |   Supports runtime evaluation: No  |   Data bindable:

defaultValue
Required: No  |   Supports runtime evaluation: Yes  |   Data bindable:

disabled
Required: No  |   Supports runtime evaluation: Yes  |   Data bindable:

labelStyle
Required: No  |   Supports runtime evaluation: Yes  |   Data bindable:

labelStyleClass
Required: No  |   Supports runtime evaluation: Yes  |   Data bindable:

optionsDataSource
Required: No  |   Supports runtime evaluation: Yes  |   Data bindable:

orientation
Required: No  |   Supports runtime evaluation: Yes  |   Data bindable:

repeater
Required: No  |   Supports runtime evaluation: Yes  |   Data bindable:

style
Required: No  |   Supports runtime evaluation: Yes  |   Data bindable:

styleClass
Required: No  |   Supports runtime evaluation: Yes  |   Data bindable:


 
Example

In this first sample, the <netui:checkBoxGroup> submits data to the Form Bean field preferredColors.

        <netui:checkBoxGroup
                  dataSource="{actionForm.preferredColors}"
                  optionsDataSource="{pageFlow.colors}" />
The optionsDataSource attribute points to a String[] on the Controller file:
        colors = new String[] {"Red", "Blue", "Green", "Yellow", "White", "Black"};
This automatically renders the appropriate set of checkbox options within the <checkBoxGroup>:
        <input type="checkbox" value="Red">Red</input>
        <input type="checkbox" value="Blue">Blue</input>
        <input type="checkbox" value="Green">Green</input>
        <input type="checkbox" value="Yellow">Yellow</input>
        <input type="checkbox" value="White">White</input>
        <input type="checkbox" value="Black">Black</input>
The defaultValue attribute may point to a String or a String[].
        defaultValue = new String ("Blue");
        defaultValue = new String[] {"Red", "Blue"};
In either case, the appropriate checkbox options will appear checked in the browser.
        <input type="checkbox" value="Red" checked="true">Red</input>
        <input type="checkbox" value="Blue" checked="true">Blue</input>
        <input type="checkbox" value="Green">Green</input>
        <input type="checkbox" value="Yellow">Yellow</input>
        <input type="checkbox" value="White">White</input>
        <input type="checkbox" value="Black">Black</input>