You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Ilja von Nagel <il...@gmail.com> on 2009/06/10 03:39:02 UTC

Two null choices in a DropDownChoice?

Does anyone know of a simple way to have more than one option with a
null value in a DropDownChoice?

Like:

--- Any Name ----
--- Names Don't Matter ----
George
Peter
Anne
Linda

Where "--- Names Don't Matter -----" would have a null value, just
like "Any Name"

I've tried adding a null value to the list of choices and then, in
getDisplayValue(), providing a display value for null value.

This will actually create the menu fine during initial render.

However, when I submit my form and the menu is re-rendered (this is a
non-Ajax filter form that is always displayed above search results, so
it is always re-rendered after form submit), I run into an NPE in
AbstractSingleSelectChoice.

Anybody have any ideas? Much appreciated!

Ilja

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


SV: Two null choices in a DropDownChoice?

Posted by Wilhelmsen Tor Iver <To...@arrive.no>.
> Does anyone know of a simple way to have more than one option 
> with a null value in a DropDownChoice?

Well, how would you disambiguate between them? Null usually means
"unset" in the context of DDC, but here you have semantic meanings to
the choices, so they should be "real" objects.

A better solution is to have "constant values" that you treat specially,
e.g. if the domain objects are of type Name, add two elements at the top
of the list for the DDC.

public class Name {

	public static final Name ANY_VALUE = new Name(-1, "--- Any Name
----");
	public static final Name NO_MATTER_VALUE = new Name(-2, "---
Names Don't Matter ----");

...
	private int id;
	private String name;
...

}

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