Re: ListView (or other Repeater) with backing map
On Mon, 30 Apr 2012 10:25:21 -0700 (PDT) cmagnollay cmagnol...@gmail.com wrote: So essentially I want to use Wicket 1.5 to display an item and its associated quantity. The data structure I am using to back this is a Map (new HashMap()) where Item is a POJ whose details are of no consequence. Essentially I would like to use one of wicket's repeaters, but I only have experience using ListView. Is there a repeater that would work well with a Map, or am I going to need to code my own? If I need to code my own, what is the best class to override? The List has has key-value pairs of type: Item-Integer where integer is the quantity. I'd just use Map#entrySet, which gives you a SetMap.EntryItem,Integer. You can turn that into a list and feed it to a ListViewMap.EntryItem,Integer. That way you have an Entry in each ListItem and can simply use its two parts. Hope this helps. Carl-Eric - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: ListView (or other Repeater) with backing map
if the map is called something like MapItem, Integer itemMap = new HashMapItem, Integer(); Hmm, so I would instantiate the ListView like so? ListViewListlt;Map.Entrylt;Item, Integer lv = new ListViewListlt;Map.Entrylt;Item, Integer(id, new PropertyModelListlt;Map.Entrylt;Item, Integer(this, itemMap.entrySet()){ populateItem(Map.EntryItem, Integer entry) { } } Is this what you are implying somewhat? Thanks for the answer by the way, I had not considered just, for lack of a better term, fooling the listview into using my map elements. -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/ListView-or-other-Repeater-with-backing-map-tp4598817p4598865.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: ListView (or other Repeater) with backing map
On Mon, 30 Apr 2012 10:43:30 -0700 (PDT) cmagnollay cmagnol...@gmail.com wrote: if the map is called something like MapItem, Integer itemMap = new HashMapItem, Integer(); Hmm, so I would instantiate the ListView like so? [...] Is this what you are implying somewhat? Thanks for the answer by the way, I had not considered just, for lack of a better term, fooling the listview into using my map elements. Basically yes, though the propertymodel won't work like that. I'd do something like this (pseudocode): MapItem,Integer itemMap = ...; IModelListMap.EntryItem,Integer mapListModel = new LoadableDetachableModel() { load() { return new ArrayList...(itemMap.entrySet()); } }; ...new ListViewMap.Entry...(id, mapListModel) { populateItem(ListItemItem,Integer li) { ... } } Carl-Eric - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: ListView (or other Repeater) with backing map
And I can force the model to update, via AJAX, or in other words, how I force the list view to update after a user action? onUpdate(AjaxRequestTarget target) { target.add(theListView) ?? } or is it something I do with the model itself? Sorry, I have no experience with LoadableDetachable, and a quick glance at the API did not enlighten me. My guess would be to give the listview a new model on each trigger of the AJAX code. -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/ListView-or-other-Repeater-with-backing-map-tp4598817p4599009.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: ListView (or other Repeater) with backing map
You can call LDM#detach() after the modification, but since this particular implementation is so light, I'd just use AbstractReadyOnlyModel instead. It doesn't cache, so detach is not required. On Mon, Apr 30, 2012 at 11:36 AM, cmagnollay cmagnol...@gmail.com wrote: And I can force the model to update, via AJAX, or in other words, how I force the list view to update after a user action? onUpdate(AjaxRequestTarget target) { target.add(theListView) ?? } or is it something I do with the model itself? Sorry, I have no experience with LoadableDetachable, and a quick glance at the API did not enlighten me. My guess would be to give the listview a new model on each trigger of the AJAX code. -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/ListView-or-other-Repeater-with-backing-map-tp4598817p4599009.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: ListView (or other Repeater) with backing map
On Mon, 30 Apr 2012 11:38:36 -0700 Dan Retzlaff dretzl...@gmail.com wrote: You can call LDM#detach() after the modification, but since this particular implementation is so light, I'd just use AbstractReadyOnlyModel instead. It doesn't cache, so detach is not required. Actually, getObject() can be called pretty often, so that would incur the cost of creating the new List object *each time*. I would really use the LDM. Since in my example the LDM is passed directly into the ListView as its default model, the ListView will take care of detaching [1]. cmagnollay, that means that on each render you should simply see whatever is currently in your map, so it should be up to date on its own without further action. An LDM calls the load() method the first time its getObject() is called. The value you return from load() will be cached until detach() is called on the LDM. The normal usecase is to do an expensive operation (load from DB, create a lot of objects, etc) only once in a request but to still have fresh data in each request. Also it reduces session size because the cached data is not kept between requests. Hope this helps! Carl-Eric [1] Carl-Eric's rule of detaching models: *always* do one of the following: - detach the model yourself - pass the model to one of your child components or your superclass, thus making it that code's responsibility. You never know what model implementation you might be getting as a parameter. Be nice to whoever calls you. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: ListView (or other Repeater) with backing map
I assumed the action phase would dereference the ListItemModel (e.g. to remove it from the map), hence dereference the LDM, and then require the explicit detach() before rendering. Agreed that LDM is the way to go if you're concerned about the ArrayList constructions. On Mon, Apr 30, 2012 at 11:57 AM, Carl-Eric Menzel cmen...@wicketbuch.dewrote: On Mon, 30 Apr 2012 11:38:36 -0700 Dan Retzlaff dretzl...@gmail.com wrote: You can call LDM#detach() after the modification, but since this particular implementation is so light, I'd just use AbstractReadyOnlyModel instead. It doesn't cache, so detach is not required. Actually, getObject() can be called pretty often, so that would incur the cost of creating the new List object *each time*. I would really use the LDM. Since in my example the LDM is passed directly into the ListView as its default model, the ListView will take care of detaching [1]. cmagnollay, that means that on each render you should simply see whatever is currently in your map, so it should be up to date on its own without further action. An LDM calls the load() method the first time its getObject() is called. The value you return from load() will be cached until detach() is called on the LDM. The normal usecase is to do an expensive operation (load from DB, create a lot of objects, etc) only once in a request but to still have fresh data in each request. Also it reduces session size because the cached data is not kept between requests. Hope this helps! Carl-Eric [1] Carl-Eric's rule of detaching models: *always* do one of the following: - detach the model yourself - pass the model to one of your child components or your superclass, thus making it that code's responsibility. You never know what model implementation you might be getting as a parameter. Be nice to whoever calls you. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: ListView (or other Repeater) with backing map
Thank for you all for the response. I am trying to test that code but am having a different separate issue at the moment. Your solutions however worked exactly as intended. Thank you for all the help! -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/ListView-or-other-Repeater-with-backing-map-tp4598817p4599149.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: ListView (or other Repeater) with backing map
On Mon, 30 Apr 2012 12:15:20 -0700 Dan Retzlaff dretzl...@gmail.com wrote: I assumed the action phase would dereference the ListItemModel (e.g. to remove it from the map), hence dereference the LDM, and then require the explicit detach() before rendering. Agreed that LDM is the way to go if you're concerned about the ArrayList constructions. That assumption depends very much on the code you give the model to. Many places will simply call getObject() instead of keeping a reference to whatever is inside. PropertyModel is one of them that is very commonly used. Carl-Eric - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org