Wicket DropDownChoice Question about Constructors and its Behavior
Hi all, since I'm working with Wicket I am a bit confused about the Constructors of DropDownChoice Class. DropDownChoice provides Constructors without any Model or ModelObject. e.g. (id, List choices) This is logical in an use-case, for instance, having just a page with a SelectBox and my first click is about to choose something. And I may do not have any parent model object of the page, so I did not bind my DropDownChoice by PropertyModel expressions. So, in such cases... Why Wicket always complaints about try to set ModelObject of null model? Yes, I explicitly decided to use DropDownChoice without a model. Since nothing is chosen, the model object of the DropDownChoice is null. The behavior I expect is, the model object is the chosen option (object) after selecting one. But it seems, it does not work like this. Can someone please light me. :-) kind regards Patrick - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Wicket DropDownChoice Question about Constructors and its Behavior
Hi, This use case will work only when the DropDownChoice has a parent in the hierarchy with org.apache.wicket.model.IComponentInheritedModel, like org.apache.wicket.model.CompoundPropertyModel. In this case the dropdown will use a slot from its parent's IComponentInheritedModel. On Thu, Sep 26, 2013 at 9:39 AM, Patrick Davids patrick.dav...@nuboit.dewrote: Hi all, since I'm working with Wicket I am a bit confused about the Constructors of DropDownChoice Class. DropDownChoice provides Constructors without any Model or ModelObject. e.g. (id, List choices) This is logical in an use-case, for instance, having just a page with a SelectBox and my first click is about to choose something. And I may do not have any parent model object of the page, so I did not bind my DropDownChoice by PropertyModel expressions. So, in such cases... Why Wicket always complaints about try to set ModelObject of null model? Yes, I explicitly decided to use DropDownChoice without a model. Since nothing is chosen, the model object of the DropDownChoice is null. The behavior I expect is, the model object is the chosen option (object) after selecting one. But it seems, it does not work like this. Can someone please light me. :-) kind regards Patrick - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Wicket DropDownChoice Question about Constructors and its Behavior
I think if you do not provide a model wicket will try to find a parent with a IComponentInheritedModel and use that as the model (to set the object with the same name you passed as ID) On Thu, Sep 26, 2013 at 9:39 AM, Patrick Davids patrick.dav...@nuboit.dewrote: Hi all, since I'm working with Wicket I am a bit confused about the Constructors of DropDownChoice Class. DropDownChoice provides Constructors without any Model or ModelObject. e.g. (id, List choices) This is logical in an use-case, for instance, having just a page with a SelectBox and my first click is about to choose something. And I may do not have any parent model object of the page, so I did not bind my DropDownChoice by PropertyModel expressions. So, in such cases... Why Wicket always complaints about try to set ModelObject of null model? Yes, I explicitly decided to use DropDownChoice without a model. Since nothing is chosen, the model object of the DropDownChoice is null. The behavior I expect is, the model object is the chosen option (object) after selecting one. But it seems, it does not work like this. Can someone please light me. :-) kind regards Patrick - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org -- Regards - Ernesto Reinaldo Barreiro
Re: Wicket DropDownChoice Question about Constructors and its Behavior
Hmm... ok, does that mean, in forms I do not have to wrap my model(object) into a CompundPropertyModel, because DropDownList (or even all FormComponents?) automatically joins IComponentInheritedModel hierarchy? So, as conclusion, by using a constuctor with an empty model (id, new Model(), List choices) a exclude my DropDownChoice from the hierarchy? Patrick Am 26.09.2013 09:47, schrieb Martin Grigorov: Hi, This use case will work only when the DropDownChoice has a parent in the hierarchy with org.apache.wicket.model.IComponentInheritedModel, like org.apache.wicket.model.CompoundPropertyModel. In this case the dropdown will use a slot from its parent's IComponentInheritedModel. On Thu, Sep 26, 2013 at 9:39 AM, Patrick Davids patrick.dav...@nuboit.dewrote: Hi all, since I'm working with Wicket I am a bit confused about the Constructors of DropDownChoice Class. DropDownChoice provides Constructors without any Model or ModelObject. e.g. (id, List choices) This is logical in an use-case, for instance, having just a page with a SelectBox and my first click is about to choose something. And I may do not have any parent model object of the page, so I did not bind my DropDownChoice by PropertyModel expressions. So, in such cases... Why Wicket always complaints about try to set ModelObject of null model? Yes, I explicitly decided to use DropDownChoice without a model. Since nothing is chosen, the model object of the DropDownChoice is null. The behavior I expect is, the model object is the chosen option (object) after selecting one. But it seems, it does not work like this. Can someone please light me. :-) kind regards Patrick - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org -- Mit freundlichen Grüßen, Patrick Davids NuboIT GmbH Co. KG Kieler Str. 103-107 • 25474 Bönningstedt Email: patrick.dav...@nuboit.de Handelsregister: HRA6819 Pi | Amtsgericht Pinneberg Geschäftsführung der Verwaltungsgesellschaft Daniel Fraga Zander HRB10145Pi | Amtsgericht Pinneberg - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Wicket DropDownChoice Question about Constructors and its Behavior
See section 9.2.2 CompoundPropertyModel and model inheritance of the Wicket Free Guide: http://wicket.apache.org/learn/books/freeguide.html Direct link: https://wicket-guide.googlecode.com/files/Wicket%20free%20guide.pdf#page77 I think you're confusing components with null models (hence they look up the wicket components hierarchy for a ConpoundPropertyModel to use) with components using empty new Model() models. When you define an empty model the user input will start out blank as you would expect. The same can be done if your (Compound)PropertyModel resolves to a POJO with a property whose value is null. If you don't specify a model at all, and none of your component's parents have a CompoundPropertyModel or they do but don't match your component's ID, then you're in troubles and you'll get you null model error. Have a great day, Paul Bors On Sep 26, 2013, at 3:57 AM, Patrick Davids patrick.dav...@nuboit.de wrote: Hmm... ok, does that mean, in forms I do not have to wrap my model(object) into a CompundPropertyModel, because DropDownList (or even all FormComponents?) automatically joins IComponentInheritedModel hierarchy? So, as conclusion, by using a constuctor with an empty model (id, new Model(), List choices) a exclude my DropDownChoice from the hierarchy? Patrick Am 26.09.2013 09:47, schrieb Martin Grigorov: Hi, This use case will work only when the DropDownChoice has a parent in the hierarchy with org.apache.wicket.model.IComponentInheritedModel, like org.apache.wicket.model.CompoundPropertyModel. In this case the dropdown will use a slot from its parent's IComponentInheritedModel. On Thu, Sep 26, 2013 at 9:39 AM, Patrick Davids patrick.dav...@nuboit.dewrote: Hi all, since I'm working with Wicket I am a bit confused about the Constructors of DropDownChoice Class. DropDownChoice provides Constructors without any Model or ModelObject. e.g. (id, List choices) This is logical in an use-case, for instance, having just a page with a SelectBox and my first click is about to choose something. And I may do not have any parent model object of the page, so I did not bind my DropDownChoice by PropertyModel expressions. So, in such cases... Why Wicket always complaints about try to set ModelObject of null model? Yes, I explicitly decided to use DropDownChoice without a model. Since nothing is chosen, the model object of the DropDownChoice is null. The behavior I expect is, the model object is the chosen option (object) after selecting one. But it seems, it does not work like this. Can someone please light me. :-) kind regards Patrick - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org -- Mit freundlichen Grüßen, Patrick Davids NuboIT GmbH Co. KG Kieler Str. 103-107 • 25474 Bönningstedt Email: patrick.dav...@nuboit.de Handelsregister: HRA6819 Pi | Amtsgericht Pinneberg Geschäftsführung der Verwaltungsgesellschaft Daniel Fraga Zander HRB10145Pi | Amtsgericht Pinneberg - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
DropDownChoice Question
Hey everyone, I am relatively new to using Wicket, and I have a question about using DropDownChoice's to put a select box on a form. I want to display choices which have specific ID values for each option (instead of indexed choices, like most examples I see), and I want to update a String variable in the object that I am editing based on the ID that is selected. I basically want a DropDownChoice that works like a TextField, where the value updated in the Model is the ID of the selected option. I created the following SelectChoice class so that I can create choices, and render them with new ChoiceRenderer(id,value)... public class SelectChoice implements Serializable { public String id; public String display; public SelectChoice (String id, String display){ this.id=id; this.display=display; } } This allows me to properly display the data, but now I get class cast exceptions, unless the model that I pass in has a SelectOption as its object. My main question: Is there an easy way to extend/customize the DropDownChoice component, so that it renders choices from a class like SelectChoice, which has an id / displayValue pair, but allows me to use a simple PropertyModel as my model, which updates a String variable with the results of selecting a choice from the dropdown? For Example I have the an Item class to handle the data: private static class Item implements Serializable{ private String itemid; private String name; private String description; private String type; private Collection groups; public Item(String itemid, String name, String description,String type,Collection groups){ this.itemid=itemid; this.name=name; this.description=description; this.type=type; this.groups=groups; } } And I want to be able to add a DropDownChoice to my form that is something like this and have it automatically update Item.type in my model: public class EditItemForm extends Form{ public EditItemForm(final String id, final Item item){ super(id, new CompoundPropertyModel(item)); List choices = new ArrayList(); choices.add(new Options(1001,Choice1)); choices.add(new Options(2004,Choice4)); choices.add(new Options(305,Choice5)); final DropDownChoice ddc = new DropDownChoice(ddc,new PropertyModel(theItem,type),choices,new ChoiceRenderer(display,id) ); add(ddc); } public final void onSubmit(){ getRequestCycle().setRedirect(false); System.out.println(onSubmit() - theItem.type: +theItem.type); } protected void validate(){ super.validate(); getRequestCycle().setRedirect(false); } } Thanks in advance for any pointers!! -Clay
RE: DropDownChoice Question
Hey John, Thanks for your advice, the example you gave me should handle what I need to do. -Clay -Original Message- From: John Krasnay [mailto:[EMAIL PROTECTED] Sent: Thursday, September 20, 2007 12:15 PM To: users@wicket.apache.org Subject: Re: DropDownChoice Question On Thu, Sep 20, 2007 at 11:33:31AM -0400, Clay Lehman wrote: And I want to be able to add a DropDownChoice to my form that is something like this and have it automatically update Item.type in my model: public class EditItemForm extends Form{ public EditItemForm(final String id, final Item item){ super(id, new CompoundPropertyModel(item)); List choices = new ArrayList(); choices.add(new Options(1001,Choice1)); choices.add(new Options(2004,Choice4)); choices.add(new Options(305,Choice5)); final DropDownChoice ddc = new DropDownChoice(ddc,new PropertyModel(theItem,type),choices,new ChoiceRenderer(display,id) ); add(ddc); } public final void onSubmit(){ getRequestCycle().setRedirect(false); System.out.println(onSubmit() - theItem.type: +theItem.type); } protected void validate(){ super.validate(); getRequestCycle().setRedirect(false); } } Hi Clay, The trick with DropDownChoice that most people seem to miss is that the objects that you put in the choices model must be of the same type as the property you're setting. Since your property is a setting is a String, you want to make your choices a list of the possible Strings to which to set it. Try something like this... final MapString, String choiceMap = new HashMapString, String(); choiceMap.put(1001, Choice 1); choiceMap.put(2004, Choice 4); choiceMap.put(305, Choice 5); ListString choices = new ArrayListString(); choices.add(1001); choices.add(2004); choices.add(305); DropDownChoice ddc = new DropDownChoice( ddc, new PropertyModel(theItem, type), choices, new IChoiceRenderer() { public Object getDisplayValue(Object object) { return choiceMap.get(object.toString()); } public String getIdValue(Object object, int index) { return object.toString(); } }); jk - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]