Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

The W3C specification does not provide a way to submit a "cleared" or "false" checkbox. If the control is clear, the browser will not submit any value for that control. The application is expected to notice that the checkbox was not submitted, and proceed accordingly.

The framework automatically tracks the checkboxes used by a form (so you don't have to). If a checkbox is missing, a default value for the checkbox (usually false) is injected. The checkbox control can then turn on-and-off values as needed,

Using Checkboxes to Set a Collection

Using Checkboxes (General)

The biggest gotcha for newbies is that you must set the 'value' attribute in the html <input> field to use Checkboxes with WW. By default your browser will set this to some value. Firefox uses "on" - not sure what IE or others use. You must make this a sensible value for whatever property you are setting.

Using Checkboxes to set boolean fields

HTML:

Code Block

<input type="checkbox" name="user.lockedOut" value="true"/>

If the user checks this box, the browser will send "user.lockedOut=true" in the QueryString and action.getUser().setLockedOut(true) will be called. If the user does not check the box, the browser will not send anything, so make sure that you have initialised lockedOut to false to start with.

Code Block

    private boolean m_lockedOut = false;

    public void setLockedOut(boolean lockedOut) { m_lockedOut = lockedOut; }

...

Our user has a number of priviliges that are stored as a Set of strings. To use checkboxes for these, we have HTML that looks like:

...

This example uses a kind-of model-driven action (see Model Driven Interceptor). The action returns a single getter for the User object whose values are populated.