Since it wasn't there, I extended DropDownChoice to encapsulate the whole
name/value pair thing:
package ****.****.****.helper.ui;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.wicket.markup.html.form.ChoiceRenderer;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.model.AbstractPropertyModel;
public class EasyDropDownChoice extends DropDownChoice
{
public EasyDropDownChoice(String componentId, AbstractPropertyModel
model, String[][] options)
{
this(componentId, model, toList(options));
}
public EasyDropDownChoice(String componentId, AbstractPropertyModel
model, Map options)
{
this(componentId, model, toList(options));
}
public EasyDropDownChoice(String componentId, AbstractPropertyModel
model, List<NameValuePair> options)
{
super(componentId, model, options, new ChoiceRenderer("value",
"id"));
}
private static List<NameValuePair> toList(String[][] choices)
{
ArrayList<NameValuePair> options = new
ArrayList<NameValuePair>();
for (int n = 0; n < choices.length; n++)
{
options.add(new NameValuePair(choices[n][0],
choices[n][1]));
}
return options;
}
private static List<NameValuePair> toList(Map<String, String> choices)
{
ArrayList<NameValuePair> options = new
ArrayList<NameValuePair>();
for (String key: choices.keySet())
{
options.add(new NameValuePair(key, choices.get(key)));
}
return options;
}
}
Which depends on:
package ***.*****.****.helper.ui;
import java.io.Serializable;
public class NameValuePair implements Serializable
{
private String id;
private String value;
public NameValuePair(String id, String value)
{
this.id = id;
this.value = value;
}
public String getId()
{
return id;
}
public void setId(String id)
{
this.id = id;
}
public String getValue()
{
return value;
}
public void setValue(String value)
{
this.value = value;
}
}
To initialize it with an array of choices, you now just have to do this:
String[][] eventTimes = new String[][] { {"7:00:00", "7:00 AM"},
{"8:00:00", "8:00 AM"},
{"9:00:00", "9:00 AM"},
{"10:00:00", "10:00 AM"},
{"11:00:00", "11:00 AM"},
{"12:00:00", "12:00 PM"},
{"13:00:00", "1:00 PM"},
{"14:00:00", "2:00 PM"},
{"15:00:00", "3:00 PM"},
{"16:00:00", "4:00 PM"},
{"17:00:00", "5:00 PM"},
{"18:00:00", "6:00 PM"} };
add(new EasyDropDownChoice("eventTime", new PropertyModel(this, "eventTime"),
eventTimes));
You can construct it with either a nested string array or a Map. Just have to
make sure the property it's bound to is of type NameValuePair.
-Andrew
_______________________________________________________
The information in this email or in any file attached
hereto is intended only for the personal and confiden-
tial use of the individual or entity to which it is
addressed and may contain information that is propri-
etary and confidential. If you are not the intended
recipient of this message you are hereby notified that
any review, dissemination, distribution or copying of
this message is strictly prohibited. This communica-
tion is for information purposes only and should not
be regarded as an offer to sell or as a solicitation
of an offer to buy any financial product. Email trans-
mission cannot be guaranteed to be secure or error-
free. P6070214
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]