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!
Here's the form:
private final class EditProductForm extends Form {
public EditProductForm(String id, Product product) {
super(id, new CompoundPropertyModel(product));
Product p = (Product) getModelObject();
System.out.printf("category: %s", product.getCategory
().getName());
System.out.printf("manufacturer: %s", product.getManufacturer
().getName());
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
(),
new ChoiceRenderer("name", "id")));
add(new DropDownChoice("manufacturer", catalogService
.getManufacturers(), new ChoiceRenderer("name", "id")));
}
@Override
protected void onSubmit() {
Product product = (Product) getModelObject();
product.setEntryDate(new Timestamp(System.currentTimeMillis()));
adminService.updateProduct(product);
setResponsePage(ViewProductsPage.class);
}
}
Cheers for all the help!
Best,
James.
On 11/5/07, James Perry <[EMAIL PROTECTED]> wrote:
>
> 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]
> > >
> > >
> >
>