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

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:

Code Block
Wiki Markup



h2. 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.  Firebird uses "on" - not sure what IE or others use.  You must make this a sensible value for whatever property you are setting.
h2. Using Checkboxes to set boolean fields
HTML:
{code}
<input type="checkbox" name="user.lockedOut" value="true"/>
{code}

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}
    private boolean m_lockedOut = false;

    public void setLockedOut(boolean lockedOut) { m_lockedOut = lockedOut; }
{code}
h2. Using Checkboxes to set a collection
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:

{code}
<input type="checkbox" name="user.priv" value="boss"/>
<input type="checkbox" name="user.priv" value="admin"/>
<input type="checkbox" name="user.priv" value="manager"/>
{code}

Say

...

a

...

user

...

checks

...

the

...

first

...

2;

...

the

...

browser

...

will

...

send

...

the

...

query

...

string:

...

user.priv=boss&user.priv=admin.

...

OGNL

...

will

...

end

...

up

...

calling

Code Block
 action.getUser().setPriv(String[] {"boss", "admin"})

You

...

can

...

write

...

this

...

method

...

like:

{
Code Block
}
    Set m_privileges = new HashSet();

    public void setPriv(String[] privs) {
        for (int i = 0; i < privs.length; i++) {
            m_privileges.add(privs[i]);
        }
    }
{code}
h2. Full Detailed 

Full Detailed example:

...

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.