my solution was going to work fine because the id came from the product configuration you are iterating over in the listview. it is not encoded in the dropdown but rather in the model that you attach to it. take a closer look.

-Igor


On 3/26/06, Vincent Jenks <[EMAIL PROTECTED]> wrote:
OK, I finally sat down and tried to work through this solution but what you've posted isn't going to solve my problem.

On this page, what I *really* need to capture is the value from the dropdown lists for each of the configurations.  The dropdowns don't contain the IDs of the configurations like your code sample...they contain a static list of numbers 0-9 - the user is selecting the quantity they would like of each product configuration to add to their shopping cart.

I need to know which item(s) they chose and what quantity they'd like.

I had done something similar to what you described only I was capturing each of the Configuration objects in a global List field...but they still don't have the updated "quantity" values the user selects.

To be more clear, I'll post the entire page class:

public class ProductDetail extends WebPage
{
    private Map<Long, Long> selection = new HashMap<Long, Long>();
   
    public ProductDetail()
    {
        this(null);
    }

    public ProductDetail(Product product)
    {
        if (product == null) setResponsePage(new ProductCatalog());

        add(new FeedbackPanel("feedbackPanel"));
       
        //modify thumbnail img tag
        WebMarkupContainer wmc = new WebMarkupContainer("photoImg");
        wmc.add(new AttributeModifier("src", new Model("assets/images/" + product.getPhoto())));
        add(wmc);
       
        //add product labels
        add(new Label("longName", product.getLongName()));
        add(new Label("summary", product.getSummary ()));
        add(new Label("description", product.getDescription()));
       
        Form form = new Form("productDetailForm");
       
        form.add(new ListView("configs", product.getConfigurations())
        {
            protected void populateItem(ListItem item)
            {
                //get object
                final Configuration config = (Configuration)item.getModelObject();           
                final Long cfgId = config.getConfigId();
               
        IModel selectionModel = new Model()
        {
          public void setObject(Component c, Object o)
          {
             selection.put(cfgId, (Long)o);
          }

            public Object getObject(Component c)
            {
                return selection.get(cfgId);
            }
        };
               
                //qty select values
                List<String> choices = Arrays.asList(
                        new String[] {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"});
               
                //add labels
                String detail = String.valueOf(config.getQuantity()) + " " +
                config.getName() + " " +
                config.getWeight ();
                item.add(new Label("fullDescription", detail));
                item.add(new Label("price", String.valueOf(config.getPrice())));
               
                //add quantity select list
                DropDownChoice ddc = new DropDownChoice("quantity", choices);
                ddc.setChoiceRenderer(new IChoiceRenderer()
                {
                    public String getDisplayValue(Object object)
                    {
                        return object.toString();
                    }
                   
                    public String getIdValue(Object object, int index)
                    {
                        return object.toString();
                    }                       
                });
               
                item.add(ddc);
            }
        });
       
        form.add(new Button("addToCartButton")
        {
            public void onSubmit()
            {
                info("Saved model " + getModelObject());
            }
        });
       
        add(form);
    }

So, in this case, when I submit the form I get an exception because there *is* no model object in the form.

I'm still confused on how I can make this work w/ Wicket...I've been screwing w/ this for 2 days and haven't made any progress.

Any ideas?


On 3/24/06, Igor Vaynberg < [EMAIL PROTECTED]> wrote:
public class MyPage extends WebPage {

private Map<Long,Integer> selection=new HashMap<Long,Integer>();

public MyPage() {
   IModel categories=....
  
   Form form=new Form("form");
   add(form);

   firm.add(new ListView("quantities", categories) {

     public void populateItem(ListItem item) {
   
         ProductCategory cat=item.getModelObject();
         final Long catId= cat.getId();

         // this model will populate an appropriate entry in the selection map
        IModel selectionModel=new Model() {
             setObject(Component c, Object o) {
                selection.put (catId, (Integer)o);
            }

            Object getObject(Component c) {
               return selection.get(catId);
           }
       }

      add(new DropDownChoice("qty", selectionModel, .....)

    }

  });

 form.add(new Button() { onSubmit() { System.out.println(selection.toString()); } }

...


-Igor


On 3/24/06, Vincent Jenks <[EMAIL PROTECTED]> wrote:
It makes sense but I wouldn't know how to begin (I'm rather new to Java as well as Wicket)...is there an example in the wicket-examples somewhere? 

Would I just create a Map inside of the ListView?


On 3/24/06, Igor Vaynberg <[EMAIL PROTECTED]> wrote:
if you are using a listview there is really no way to use a compound property model. here is what you can do:

on your page create a map:configid->qty

then to the dropdown choices assign a model that will read/write a key from this map.

so when the form submits you endup with a filled in map in your page.

makes sense?


-Igor

On 3/24/06, Vincent Jenks < [EMAIL PROTECTED]> wrote:
I've attached a screenshot of what this page does.

Basically, the page you see receives a Product object in the constructor when it is called from the previous page.  Each Product has a List of Configuration objects...which you see listed in the screenshot ( i.e. 1 Bone In Ham Half 7-10 lbs @ $99.00).  Admins can define many product Configurations that the user can select on this screen.  The Configurations have an inverse relationship back to the Product so when the Configuration is added to the cart, the Product can be referenced as well.

My problem is; in this form, how can I bind a single Configuration when there are (potentially) several, per-product?

My thinking was; I could add the Product to the ShoppingCart session bean instead and it would carry the product Configuration(s) with it...assuming I could grab each Configuration from the ListView in the form (where you see the
1 "Bone In Ham Half 7-10 lbs" text and the DropDownChoice lists) and manually create the Configuration object(s) and add them to the Product before submitting the form.

Does this make sense?

Thanks again!!

On 3/24/06, Igor Vaynberg <[EMAIL PROTECTED]> wrote:
do you have a screenshot/mockup of the form? seeing it would help.

so there is a list of configurations? and the user can click on one and edit it?

-Igor



On 3/24/06, Vincent Jenks <[EMAIL PROTECTED]> wrote:
I've got a form where I can't exactly bind a model object because of the way the form is used.  On this page, the user selects from a list of product configurations (ProductConfiguration class) which belong to a Product object....so there is a one-to-many Product->ProductConfiguration.  I can't pass a ProductConfiguration object into the CompoundPropertyModel because the user may choose more than one (or can I?)  I'm thinking I need to bind the Product and manually add the ProductConfiguration objects to the product before submitting.

If I do it this way...how can I access each of the form fields programmatically, individually?  In other words...can form field values be called w/o using a CompoundPropertyModel if needed?

Also, if there's a better way to do this, please let me know!

Thanks!








Reply via email to