I set it to return selection.get(config) and it still doesn't select anything.
I have this now: IModel selectionModel = new Model() { public void setObject(Component c, Object o) { selection.put(config, Integer.parseInt((String)o)); } public Object getObject(Component c) { return selection.get(config); } }; ...which is still producing this: <select wicket:id="quantity" name="cartView:0:quantity"> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> </select> I don't want to work directly on the cart object since I have a method in another class that accepts a Map....and I'm reusing that method throughout the cart. I don't want to write another method or alter the one I have to get around this issue. It works well as it takes the map apart, determines if the object already exists, adjusts the quantity, etc. I want all cart item additions, adjustments, etc. to flow thorugh this single method. On 5/1/06, Igor Vaynberg <[EMAIL PROTECTED]> wrote:
furthermore, if you wanted you can work on your cart object directly instead of having to translate to and from the map. -Igor On 5/1/06, Igor Vaynberg <[EMAIL PROTECTED]> wrote: > > IModel selectionModel = new Model() > { > public void setObject(Component c, Object o) > { > selection.put(config, Integer.parseInt((String)o)); > } > > public Object getObject(Component c) > { > return selection.get(this); > } > }; > > > in getObject() shouldnt that be return selection.get(config); get(this) will always return null. > > > -Igor > > > > > On 5/1/06, Vincent Jenks <[EMAIL PROTECTED] > wrote: > > I'm back on this issue now after having put it on the "back-burner" > > for a short time...since I couldn't figure it out before. I had > > posted several messages about this but can't find the original emails > > to reply to, so I'm sorry to create a new thread out of an old issue! > > > > I *just can't* get this dropdown to choose an item after loading the > > model and passing it in...I've exhausted all of my own ideas and > > really need help figuring this out. > > > > I'm building a shopping cart and after selecting an item to add to > > your cart on a products-list page...you see the next page (Cart > > class). > > > > In the previous page I used a Map to store the Configuration item + > > its quantity selected by the user (Igor, you may remember my many > > posts on this issue)....I then use the Cart page to load the Map into > > the page for display. Adding & changing items in my cart revolve > > around Wicket passing this Map into it. > > > > In the Cart page I pre-load a new Map to pass into a ListView and the > > user can then adjust the quantity of the items chosen and re-submit > > the changes. > > > > Here is the entire class: > > > > ************************************************************************************ > > public class Cart extends WebPage > > { > > private Map<Configuration, Integer> selection = new > > HashMap<Configuration, Integer>(); > > > > public Cart() > > { > > //get cart from session > > final ShoppingCart cart = ((UserSession)getSession()).getCart(); > > > > //create form > > Form form = new Form("cartForm"); > > > > //add OrderLine items to map > > for (OrderLine line : cart.getOrderLines()) > > { > > selection.put(line.getConfiguration(), line.getQuantity()); > > } > > > > //add list of Configuration objects to form > > form.add(new ListView("cartView", cart.getOrderLines()) > > { > > protected void populateItem(ListItem item) > > { > > //get object > > final OrderLine line = (OrderLine)item.getModelObject(); > > > > //pull config from line > > final Configuration config = line.getConfiguration(); > > > > //store Configuration and qty in model > > IModel selectionModel = new Model() > > { > > public void setObject(Component c, Object o) > > { > > selection.put(config, Integer.parseInt((String)o)); > > } > > > > public Object getObject(Component c) > > { > > return selection.get(this); > > } > > }; > > > > //qty select values > > List<String> choices = Arrays.asList( > > new String[] {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}); > > > > //add quantity select list > > item.add(new DropDownChoice("quantity", selectionModel, choices) > > { > > protected String getDefaultChoice(final Object selected) > > { > > return ""; //get rid of "Choose One" default > > } > > > > public String getDisplayValue(Object object) > > { > > return object.toString(); > > } > > > > public String getIdValue(Object object, int index) > > { > > return object.toString(); > > } > > }); > > > > //create link w/ event handler > > item.add(new Link("removeLink") > > { > > public void onClick() > > { > > ............................ > > } > > }); > > } > > }.setOptimizeItemRemoval(true)); //must be set inside of form > > > > //add submit button > > form.add(new Button("qtyChangeButton") > > { > > public void onSubmit() > > { > > ................ > > } > > }); > > > > //add form to page > > add(form); > > } > > } > > ************************************************************************************ > > > > You'll see I declared my map at the top of the ctor: > > > > private Map<Configuration, Integer> selection = new > > HashMap<Configuration, Integer>(); > > > > Later, in the ListView I'm trying to match the users' Configuration > > objects so the quantity will automatically show in the DropDownChoice > > list in the page: > > > > IModel selectionModel = new Model() > > { > > public void setObject(Component c, Object o) > > { > > selection.put(config, Integer.parseInt((String)o)); > > } > > > > public Object getObject(Component c) > > { > > return selection.get(this); > > } > > }; > > > > However, the existing quantity does not get selected, it always > > defaults to zero, the first item in the list. The html renders like > > this: > > > > <select wicket:id="quantity" name="cartView:0:quantity"> > > <option value="0">0</option> > > <option value="1">1</option> > > <option value="2">2</option> > > <option value="3">3</option> > > <option value="4">4</option> > > <option value="5">5</option> > > <option value="6">6</option> > > <option value="7">7</option> > > <option value="8">8</option> > > <option value="9">9</option> > > </select> > > > > Now, if I were to select a quantity and re-submit...it works > > correctly...that's not the issue...the only issue I have is the > > *existing* quantity for that Configuration object is not selected by > > default...it looks bad and if the user were to accidentally submit w/o > > first selecting a quantity, it would set it to zero and remove the > > item from the cart....eep! > > > > Igor had suggested that it was a data-type conversion issue IIRC, but > > I tried turning the array into Integers: > > > > List<Integer> choices = Arrays.asList( > > new Integer[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); > > > > ...it didn't matter. > > > > When i walk through the debugger the model is getting > > populated...everything appears to go according to plan...I just can't > > nail this one! > > > > Thanks in advance, it's much appreciated!! > > > > > > ------------------------------------------------------- > > Using Tomcat but need to do more? Need to support web services, security? > > Get stuff done quickly with pre-integrated technology to make your job easier > > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > > http://sel.as-us.falkag.net/sel?cmdlnk&kid0709&bid&3057&dat1642 > > _______________________________________________ > > Wicket-user mailing list > > Wicket-user@lists.sourceforge.net > > https://lists.sourceforge.net/lists/listinfo/wicket-user > > > >
------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642 _______________________________________________ Wicket-user mailing list Wicket-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wicket-user