Hi Ray
@1 This is a typical newcommer question, I asked it myself once:). I
think you should check here:
http://cwiki.apache.org/WICKET/working-with-wicket-models.html
Basic is that you create a dropdownchoice, and pass a model to it( a
model are something that encapsulates your selected object). Then wicket
will automaticly put the selected object into the model, and if you
provide a model that already contain something wicket will automaticly
select it in the dropdown (providing that you supplied it with a list
that contains that object). If you need special rendering create your
own Ichoicerenderer, you will get the current object, return what you
want from the object to be displayed(eg from person you might return
person.getName()). I've been told that the ID part you can get away with
just returning the id again.
@2
You can use the latter approach overiding the protected method, but
remember that it goes in conjunction with
wantOnSelectionNotificationChanges or something like that must be
overriden aswell returning true.
BTW: say if you need more information.
regards Nino
raybristol wrote:
Hi, I am quite new to wicket and got 2 questions about DropDownChoice don't
know how to solve even after some googling as well from this forum so need
some helps again:
1. I want to get the current selected item's value from DropDownChoice, I
was looking for something like
DropDownChoiceObject.selectedValueOrID() - something equitvalent, I saw the
example from wicket website, it's using:
DropDownChoice ddc =
new DropDownChoice("name",
new PropertyModel(employee, "managedBy"),
new LoadableDetachableModel() {
...
}
);
so do I have to pass in a PropertyModel to achieve what I want? mine is:
final Map<String, String> choiceMap = new HashMap<String, String>();
final List<String> jpNameString = new ArrayList();
for (JobProfile j : jobProfiles){
choiceMap.put(String.valueOf(j.getId()), j.getName());
jpNameString.add(String.valueOf(j.getId()));
}
IChoiceRenderer renderer = new ChoiceRenderer() {
public Object getDisplayValue(Object object) {
return choiceMap.get(object);}
public String getIdValue(Object object, int index) {
return object.toString();
}
};
final DropDownChoice ddc = new DropDownChoice(
"filterByJobProfileName", jpNameString, renderer)
2. my second question is how to use event OnSelectionChange, I saw two
events from the API, one is final so I can't overide, one is pretected:
final void onSelectionChanged()
protected void onSelectionChanged(java.lang.Object newSelection)
I can't use either like:
final DropDownChoice ddc = new DropDownChoice( "filterByJobProfileName",
jpNameString, renderer){
void onSeclectionChanged(){
//I want to do somethign here if this is working :(
}
};
Many thanks for your help!
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]