You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by eugenebalt <eu...@yahoo.com> on 2013/06/21 17:09:24 UTC

Set the Null option manually in a NullValid Dropdown

We have a dropdown which supports the NullValid property.

If we need to set its selection to Null manually, setModel(null) does not
seem to work. Should we set it to the first element of the backing model
(which is an KeyValueBean list)?



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Set-the-Null-option-manually-in-a-NullValid-Dropdown-tp4659670.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: Set the Null option manually in a NullValid Dropdown

Posted by Paul Bors <pa...@bors.ws>.
As per the JavaDoc:

AbstractSingleSelectChoice<T>
org.apache.wicket.markup.html.form.AbstractSingleSelectChoice.setNullValid(b
oolean nullValid)

Determines whether or not the null value should be included in the list of
choices when the field's model value is nonnull, and whether or not the
null_valid string property (e.g. "Choose One") should be displayed until a
nonnull value is selected. 

If set to false, then "Choose One" will be displayed when the value is null.
After a value is selected, and that change is propagated to the underlying
model, the user will no longer see the "Choose One" option, and there will
be no way to reselect null as the value.

If set to true, the null string property (the empty string, by default) will
always be displayed as an option, whether or not a nonnull value has ever
been selected. Note that this setting has no effect on validation; in order
to guarantee that a value will be specified on form validation,
setRequired(boolean).

This is because even if setNullValid() is called with false, the user can
fail to provide a value simply by never activating (i.e. clicking on) the
component.

If I'm not mistaken your code should looks something like this:

// Instruct Wicket to always display the null value in your select
dropDownChoice.setNullValid(true);
// We want the user to select null so this is no longer a required field
dropDownChoice.setRequired(false);

If you want to change the label this null is mapped to from "Choose One" to
something else:
dropDownChoice = new DropDownChoice<M>(LabeledFormField.FIELD_ID, model,
choices) {
    @Override
    protected String getNullValidKey() {
        return "Your.Own.Language.Pack.Key";
    }
};

~ Thank you,
  Paul Bors

-----Original Message-----
From: eugenebalt [mailto:eugenebalt@yahoo.com] 
Sent: Friday, June 21, 2013 11:09 AM
To: users@wicket.apache.org
Subject: Set the Null option manually in a NullValid Dropdown

We have a dropdown which supports the NullValid property.

If we need to set its selection to Null manually, setModel(null) does not
seem to work. Should we set it to the first element of the backing model
(which is an KeyValueBean list)?



--
View this message in context:
http://apache-wicket.1842946.n4.nabble.com/Set-the-Null-option-manually-in-a
-NullValid-Dropdown-tp4659670.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org