Problem with selecting default value with DropDownChoice
I have a problem with the DropDownChoice. More specifically, I have a Product class which is like: public class Product implements Serializable { private static final long serialVersionUID = 1L; private Manufacturer manufacturer; //other states //getters and setters } I have a form which allows to edit a product, which allows to change the manufacturer object with a DropDownChoice. However, an Xbox product for instance, it should display its Microsoft manufacturer object as selected but it selects 'Choose One' instead. Also, the setRequired for the DropDownChoice does not work as it allows users to select 'Choose One'. I notice it works with primitive types but not with my compositional objects. Here is my EditProductPage: package net.sourceforge.springcart.wicket.pages.admin; public class EditProductPage extends AdminPage { private static final long serialVersionUID = 1L; @SpringBean(name = adminService) private AdminService adminService; public EditProductPage() { this(new Product()); } public EditProductPage(Product product) { MenuBorder border = new MenuBorder(libBorder); border.add(new EditProductForm(productForm, product)); add(border); } private final class EditProductForm extends Form { public EditProductForm(String id, Product product) { super(id, new CompoundPropertyModel(product)); add(new RequiredTextField(name)); add(new RequiredTextArea(description)); add(new RequiredTextField(sellValue, BigDecimal.class)); add(new RequiredTextField(units, Long.class)); add(new CheckBox(onSell).setRequired(true)); add(new DropDownChoice(category, catalogService.getCategories ()) .setRequired(true)); add(new DropDownChoice(manufacturer, catalogService .getManufacturers()).setRequired(true)); } @Override protected void onSubmit() { Product product = (Product) getModelObject(); product.setEntryDate(new Timestamp(System.currentTimeMillis())); adminService.updateProduct(product); setResponsePage(ViewProductsPage.class); } } } Any advice please? Cheers, James.
Re: Problem with selecting default value with DropDownChoice
On Monday 05 November 2007 16:39:02 James Perry wrote: I have a problem with the DropDownChoice. More specifically, I have a Product class which is like: public class Product implements Serializable { private static final long serialVersionUID = 1L; private Manufacturer manufacturer; //other states //getters and setters } I have a form which allows to edit a product, which allows to change the manufacturer object with a DropDownChoice. However, an Xbox product for instance, it should display its Microsoft manufacturer object as selected but it selects 'Choose One' instead. May be choices and value in the DDC are different java objects and you didn't implement equals(), hashCode() in Manufacturer class? Dima - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Problem with selecting default value with DropDownChoice
Provide a ChoiceRenderer to the DropDownChoice constructor. It's in the ID part of it. Frank On 11/5/07, James Perry [EMAIL PROTECTED] wrote: I have a problem with the DropDownChoice. More specifically, I have a Product class which is like: public class Product implements Serializable { private static final long serialVersionUID = 1L; private Manufacturer manufacturer; //other states //getters and setters } I have a form which allows to edit a product, which allows to change the manufacturer object with a DropDownChoice. However, an Xbox product for instance, it should display its Microsoft manufacturer object as selected but it selects 'Choose One' instead. Also, the setRequired for the DropDownChoice does not work as it allows users to select 'Choose One'. I notice it works with primitive types but not with my compositional objects. Here is my EditProductPage: package net.sourceforge.springcart.wicket.pages.admin; public class EditProductPage extends AdminPage { private static final long serialVersionUID = 1L; @SpringBean(name = adminService) private AdminService adminService; public EditProductPage() { this(new Product()); } public EditProductPage(Product product) { MenuBorder border = new MenuBorder(libBorder); border.add(new EditProductForm(productForm, product)); add(border); } private final class EditProductForm extends Form { public EditProductForm(String id, Product product) { super(id, new CompoundPropertyModel(product)); add(new RequiredTextField(name)); add(new RequiredTextArea(description)); add(new RequiredTextField(sellValue, BigDecimal.class)); add(new RequiredTextField(units, Long.class)); add(new CheckBox(onSell).setRequired(true)); add(new DropDownChoice(category, catalogService.getCategories ()) .setRequired(true)); add(new DropDownChoice(manufacturer, catalogService .getManufacturers()).setRequired(true)); } @Override protected void onSubmit() { Product product = (Product) getModelObject(); product.setEntryDate(new Timestamp(System.currentTimeMillis ())); adminService.updateProduct(product); setResponsePage(ViewProductsPage.class); } } } Any advice please? Cheers, James.
Re: Problem with selecting default value with DropDownChoice
Hi James, While the implementation's not a big deal, and you'll probably want one, Choose One is the default for when the selected (or pre-selected) item's not found in the DDC list of values, so I don't think it's directly that. I'd be tempted to double-check (either via logging or via a debugger) that all the data's there as expected (although an anonymous implementation of a IChoiceRender's as good a way as any of having somewhere to set a breakpoint!) /Gwyn Monday, November 5, 2007, 2:54:09 PM, you wrote: JP Hello Dima, JP That was my initial assumption but I already have overrided my JP equals()/hashCode() methods for Manufacturer's business key in Hibernate JP and ensured my HQL query retrieves Manufacturer objects. Do I need to add an JP implementation of IChoiceRendered as an argument to DDC? JP Thanks, JP James. JP On 11/5/07, Dmitry Kandalov [EMAIL PROTECTED] wrote: On Monday 05 November 2007 16:39:02 James Perry wrote: I have a problem with the DropDownChoice. More specifically, I have a Product class which is like: public class Product implements Serializable { private static final long serialVersionUID = 1L; private Manufacturer manufacturer; //other states //getters and setters } I have a form which allows to edit a product, which allows to change the manufacturer object with a DropDownChoice. However, an Xbox product for instance, it should display its Microsoft manufacturer object as selected but it selects 'Choose One' instead. May be choices and value in the DDC are different java objects and you didn't implement equals(), hashCode() in Manufacturer class? Dima - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Problem with selecting default value with DropDownChoice
On Monday 05 November 2007 18:55:07 James Perry wrote: Also what about wrapping the List in a PropertyModel; would that help? On 11/5/07, James Perry [EMAIL PROTECTED] wrote: Hello Dima, That was my initial assumption but I already have overrided my equals()/hashCode() methods for Manufacturer's business key in Hibernate and ensured my HQL query retrieves Manufacturer objects. Do I need to add an implementation of IChoiceRendered as an argument to DDC? Thanks, James. I think wrapping list in PropertyModel won't help. You can add IChoiceRendered but it should work without it. If you have wicket sources you can put breakpoint at AbstractSingleSelectChoice#getModelValue and see if object is really in the choices list. Dima - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Problem with selecting default value with DropDownChoice
Hello all, Thanks for the replies so far. Well I have taken the feedback and my manufacturer object and category object are certainly are there when it passed to my form. It is really bizarre as if I select a manufactuer and persist the product obejct upon the form's onSubmit, it's correctly persisted. So I don't understand why it can correctly set the manufacturer object when changing a manufacturer yet it doesn't select the correct manufacturer upon going to EditProductPage. Any thoughts? I tried it with a RadioChoice and it has the same problem. :-( On 11/5/07, Gwyn Evans [EMAIL PROTECTED] wrote: Hi James, While the implementation's not a big deal, and you'll probably want one, Choose One is the default for when the selected (or pre-selected) item's not found in the DDC list of values, so I don't think it's directly that. I'd be tempted to double-check (either via logging or via a debugger) that all the data's there as expected (although an anonymous implementation of a IChoiceRender's as good a way as any of having somewhere to set a breakpoint!) /Gwyn Monday, November 5, 2007, 2:54:09 PM, you wrote: JP Hello Dima, JP That was my initial assumption but I already have overrided my JP equals()/hashCode() methods for Manufacturer's business key in Hibernate JP and ensured my HQL query retrieves Manufacturer objects. Do I need to add an JP implementation of IChoiceRendered as an argument to DDC? JP Thanks, JP James. JP On 11/5/07, Dmitry Kandalov [EMAIL PROTECTED] wrote: On Monday 05 November 2007 16:39:02 James Perry wrote: I have a problem with the DropDownChoice. More specifically, I have a Product class which is like: public class Product implements Serializable { private static final long serialVersionUID = 1L; private Manufacturer manufacturer; //other states //getters and setters } I have a form which allows to edit a product, which allows to change the manufacturer object with a DropDownChoice. However, an Xbox product for instance, it should display its Microsoft manufacturer object as selected but it selects 'Choose One' instead. May be choices and value in the DDC are different java objects and you didn't implement equals(), hashCode() in Manufacturer class? Dima - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Problem with selecting default value with DropDownChoice
Some notes I have observed. * All my objects within the list are correctly in the DDC * All my objects within the list have an implemented equals/hashcode. * It doesn't correctly pre-select both my Manufacturer associations within Product; it just goes to 'Choose One' * It correctly sets Manufacturer if we change the pre-selected 'Choose One' to any object within the DDC. So why is it not correctly pre-selecting? For example, my Xbox is not pre-selecting to Microsoft instead going to 'Choose One'. Cheers, James. On 11/5/07, James Perry [EMAIL PROTECTED] wrote: Hello all, Thanks for the replies so far. Well I have taken the feedback and my manufacturer object and category object are certainly are there when it passed to my form. It is really bizarre as if I select a manufactuer and persist the product obejct upon the form's onSubmit, it's correctly persisted. So I don't understand why it can correctly set the manufacturer object when changing a manufacturer yet it doesn't select the correct manufacturer upon going to EditProductPage. Any thoughts? I tried it with a RadioChoice and it has the same problem. :-( On 11/5/07, Gwyn Evans [EMAIL PROTECTED] wrote: Hi James, While the implementation's not a big deal, and you'll probably want one, Choose One is the default for when the selected (or pre-selected) item's not found in the DDC list of values, so I don't think it's directly that. I'd be tempted to double-check (either via logging or via a debugger) that all the data's there as expected (although an anonymous implementation of a IChoiceRender's as good a way as any of having somewhere to set a breakpoint!) /Gwyn Monday, November 5, 2007, 2:54:09 PM, you wrote: JP Hello Dima, JP That was my initial assumption but I already have overrided my JP equals()/hashCode() methods for Manufacturer's business key in Hibernate JP and ensured my HQL query retrieves Manufacturer objects. Do I need to add an JP implementation of IChoiceRendered as an argument to DDC? JP Thanks, JP James. JP On 11/5/07, Dmitry Kandalov [EMAIL PROTECTED] wrote: On Monday 05 November 2007 16:39:02 James Perry wrote: I have a problem with the DropDownChoice. More specifically, I have a Product class which is like: public class Product implements Serializable { private static final long serialVersionUID = 1L; private Manufacturer manufacturer; //other states //getters and setters } I have a form which allows to edit a product, which allows to change the manufacturer object with a DropDownChoice. However, an Xbox product for instance, it should display its Microsoft manufacturer object as selected but it selects 'Choose One' instead. May be choices and value in the DDC are different java objects and you didn't implement equals(), hashCode() in Manufacturer class? Dima - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Problem with selecting default value with DropDownChoice
Hi James, Monday, November 5, 2007, 8:05:58 PM, you wrote: JP Some notes I have observed. * All my objects within the list are JP correctly in the DDC * All my objects within the list have an JP implemented equals/hashcode. * It doesn't correctly pre-select JP both my Manufacturer associations within Product; it just goes to JP 'Choose One' * It correctly sets Manufacturer if we change the JP pre-selected 'Choose One' to any object within the DDC. JP So why is it not correctly pre-selecting? For example, my Xbox is not JP pre-selecting to Microsoft instead going to 'Choose One'. I'm afraid that it does sound as if the pre-selected manufacturer isn't matching the ones in the list, although I'd want to run through the Wicket sources before I was happy it wasn't down to something like an Object to String conversion going on somewhere. (Random guessing, though.) Maybe trying to reproduce it in a QuickStart would help - certainly isolating the problem normally helps point to the issue and if not, would let others investigate. /Gwyn - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Problem with selecting default value with DropDownChoice
On Tuesday 06 November 2007 00:55:23 James Perry wrote: I empirically found out what the solution was to the problem of not selecting the correct default choice of the Manufacturer within Product! I added a ChoiceRendered to the constructor of DDC and it did the trick! It seems like equals() doesn't work correctly. Dima - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]