Re: problem with ChoiceRenderer
On 11.5.2012 12:21, Andrea Del Bene wrote: Hi, the type of the model and of the renderer must be the same chosen for the DropDownChoice (Vyrobok in your case). In the first version of your code this was not true for your model because it pointed to a String field (named kluc). Your second version works fine because you don't provide a property expression to PropertyModel (is null) and doing so the property model considers as model object the first parameter of its constructor (defaultChoice in your case), which is an instance of class Vyrobok. But at this point it does not make much sense to use a PropertyModel, you could substitute it with a Model class, like this: Model.of(defaultChoice) just now I have elaborated that this works: DropDownChoiceVyrobok vyberVyrobku = new DropDownChoiceVyrobok(vyberVyrobku, new PropertyModelVyrobok(defaultChoice, null), vyrobky, renderer); (note `null' in PropertyModel) but strange is that I don't know why :-( yes, now I see, mea culpa thanks for pointing me this On 11.5.2012 9:36, Sven Meier wrote: Hi, Vyrobok defaultChoice = vyrobky.get(0); DropDownChoiceVyrobok vyberVyrobku = new DropDownChoiceVyrobok( zoznam, new PropertyModelVyrobok(defaultChoice, kluc), vyrobky, renderer); you're instructing the DropDownChoice to get its model object from your defaultChoice: new PropertyModelVyrobok(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 PropertyModelVyrobok(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(); ListVyrobok vyrobky = Arrays.asList(new Vyrobok(start, -Vyberte typ-), new Vyrobok(polstar, Polštář), new Vyrobok(deka, Deka)); Vyrobok defaultChoice = vyrobky.get(0); DropDownChoiceVyrobok vyberVyrobku = new DropDownChoiceVyrobok(zoznam, new PropertyModelVyrobok(defaultChoice, kluc), vyrobky, renderer); FormObject form = new FormObject(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 IChoiceRendererVyrobok{ @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 - 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
Re: problem with ChoiceRenderer
Hi, Vyrobok defaultChoice = vyrobky.get(0); DropDownChoiceVyrobok vyberVyrobku = new DropDownChoiceVyrobok( zoznam, new PropertyModelVyrobok(defaultChoice, kluc), vyrobky, renderer); you're instructing the DropDownChoice to get its model object from your defaultChoice: new PropertyModelVyrobok(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 PropertyModelVyrobok(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(); ListVyrobok vyrobky = Arrays.asList(new Vyrobok(start, -Vyberte typ-), new Vyrobok(polstar, Polštář), new Vyrobok(deka, Deka)); Vyrobok defaultChoice = vyrobky.get(0); DropDownChoiceVyrobok vyberVyrobku = new DropDownChoiceVyrobok(zoznam, new PropertyModelVyrobok(defaultChoice, kluc), vyrobky, renderer); FormObject form = new FormObject(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 IChoiceRendererVyrobok{ @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
Re: problem with ChoiceRenderer
just now I have elaborated that this works: DropDownChoiceVyrobok vyberVyrobku = new DropDownChoiceVyrobok(vyberVyrobku, new PropertyModelVyrobok(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); DropDownChoiceVyrobok vyberVyrobku = new DropDownChoiceVyrobok( zoznam, new PropertyModelVyrobok(defaultChoice, kluc), vyrobky, renderer); you're instructing the DropDownChoice to get its model object from your defaultChoice: new PropertyModelVyrobok(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 PropertyModelVyrobok(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(); ListVyrobok vyrobky = Arrays.asList(new Vyrobok(start, -Vyberte typ-), new Vyrobok(polstar, Polštář), new Vyrobok(deka, Deka)); Vyrobok defaultChoice = vyrobky.get(0); DropDownChoiceVyrobok vyberVyrobku = new DropDownChoiceVyrobok(zoznam, new PropertyModelVyrobok(defaultChoice, kluc), vyrobky, renderer); FormObject form = new FormObject(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 IChoiceRendererVyrobok{ @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
Re: problem with ChoiceRenderer
Hi, the type of the model and of the renderer must be the same chosen for the DropDownChoice (Vyrobok in your case). In the first version of your code this was not true for your model because it pointed to a String field (named kluc). Your second version works fine because you don't provide a property expression to PropertyModel (is null) and doing so the property model considers as model object the first parameter of its constructor (defaultChoice in your case), which is an instance of class Vyrobok. But at this point it does not make much sense to use a PropertyModel, you could substitute it with a Model class, like this: Model.of(defaultChoice) just now I have elaborated that this works: DropDownChoiceVyrobok vyberVyrobku = new DropDownChoiceVyrobok(vyberVyrobku, new PropertyModelVyrobok(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); DropDownChoiceVyrobok vyberVyrobku = new DropDownChoiceVyrobok( zoznam, new PropertyModelVyrobok(defaultChoice, kluc), vyrobky, renderer); you're instructing the DropDownChoice to get its model object from your defaultChoice: new PropertyModelVyrobok(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 PropertyModelVyrobok(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(); ListVyrobok vyrobky = Arrays.asList(new Vyrobok(start, -Vyberte typ-), new Vyrobok(polstar, Polštář), new Vyrobok(deka, Deka)); Vyrobok defaultChoice = vyrobky.get(0); DropDownChoiceVyrobok vyberVyrobku = new DropDownChoiceVyrobok(zoznam, new PropertyModelVyrobok(defaultChoice, kluc), vyrobky, renderer); FormObject form = new FormObject(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 IChoiceRendererVyrobok{ @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 - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org