just now I have elaborated that this works:
DropDownChoice<Vyrobok> vyberVyrobku = new DropDownChoice<Vyrobok>("vyberVyrobku", 
new PropertyModel<Vyrobok>(defaultChoice, null), vyrobky, renderer);
(note `null' in PropertyModel)

but strange is that I don't know why :-(



On 11.5.2012 9:36, Sven Meier wrote:
Hi,

Vyrobok defaultChoice = vyrobky.get(0);
DropDownChoice<Vyrobok> vyberVyrobku =
new DropDownChoice<Vyrobok>(
"zoznam",
new PropertyModel<Vyrobok>(defaultChoice, "kluc"),
vyrobky,
renderer);

you're instructing the DropDownChoice to get its model object from your 
defaultChoice:

new PropertyModel<Vyrobok>(defaultChoice, "kluc")

This is probably not what you've intended as Kluc is a String. Something like 
the following would make more sense:

this.selectedChoice = vyrobky.get(0);

new PropertyModel<Vyrobok>(this, "selectedChoice")

Sven

On 05/11/2012 09:16 AM, Michael Jaruska wrote:
Hi folks,

after hours of elaborating, searching docu and trying I'm totaly lost. My 
ChoiceRenderer is not
working.

Here is my code (not relevant code has been removed):

markup:
<select id="1" wicket:id="zoznam"></select>

page implementation:
public class PageEshop extends PageBase{
public PageEshop(){
ChoiceRendererVyrobok renderer = new ChoiceRendererVyrobok();
List<Vyrobok> vyrobky = Arrays.asList(new Vyrobok("start", "-Vyberte typ-"), new Vyrobok("polstar", 
"Polštář"), new Vyrobok("deka", "Deka"));
Vyrobok defaultChoice = vyrobky.get(0);
DropDownChoice<Vyrobok> vyberVyrobku = new DropDownChoice<Vyrobok>("zoznam", new 
PropertyModel<Vyrobok>(defaultChoice, "kluc"), vyrobky, renderer);
Form<Object> form = new Form<Object>("inputForm");
form.add(vyberVyrobku);
this.add(form);
}
}

pojo:
public class Vyrobok implements Serializable{
private String kluc;
private String hodnota;

public Vyrobok(String kluc, String hodnota){
this.kluc = kluc;
this.hodnota = hodnota;
}
//getters and setters for attributes
}

IChoiceRenderer implementation:
public class ChoiceRendererVyrobok implements IChoiceRenderer<Vyrobok>{
@Override
public Object getDisplayValue(Vyrobok vyrobok){
return vyrobok.getHodnota();
}

@Override
public String getIdValue(Vyrobok vyrobok, int index){
return vyrobok.getKluc();
}
}

When page is loaded, this error happens (not complete stack, not relevant 
removed):
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to 
cz.polstareadeky.utils.Vyrobok
at 
cz.polstareadeky.ChoiceRendererVyrobok.getIdValue(ChoiceRendererVyrobok.java:1)
at 
org.apache.wicket.markup.html.form.AbstractSingleSelectChoice.getModelValue(AbstractSingleSelectChoice.java:194)
at 
org.apache.wicket.markup.html.form.FormComponent.getValue(FormComponent.java:837)

Something is wrong in ChoiceRendererVyrobok but I can't find what..

Any help is apreciated,

thanks, Michal

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



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


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

Reply via email to