Re: Question regarding index handling with RefreshingView and OddEvenItem
Why not use pure css for zebra striping? adding classes for odd/even is rather oldschool... tbody tr:nth-child(odd) { background-color: #ccc; } Martijn On Sun, Feb 15, 2015 at 3:56 PM, Thorsten Schöning wrote: > Hi all, > > I'm using DataView to publish some search results in a HTML table and > what the results to format zebra style. I've found OddEvenItem for > that purpose but ran into what I find is a problem: The first item is > always rendered with CSS class "even", because the index used is 0 > based. That may be correct from a technical point of view, but is not > what I want to present my users. > > So I changed my creation of OddEvenItem to simply not provide index 0, > but found that my provided index is always ignored. Even if I change > my index to a constant like 1 it is ignored. > > I found the problem in RefreshingView.addItems, where a loop is used > to iterate over items and an index is always set: > >> protected void addItems(Iterator> items) >> { >> int index = 0; >> while (items.hasNext()) >> { >> Item item = items.next(); >> item.setIndex(index); >> add(item); >> ++index; >> } >> } > > This doesn't make sense to me, because the OddEvenItem ctor is > designed to take an index, which is afterwards ignored. > > Two questions here: > > 1. Is the call to setIndex by design and one should override setIndex in > custom created items to just ignore that call? In that case the > documentation for Item should make that more clear, unless I have > missed that. > > 2. How should I get my OddEvenItem to print CSS classes based on a 1 > index at all? Should I override onComponentTag instead of changing the > index to 1 in my newItem-method? > > Thanks für help! > > Mit freundlichen Grüßen, > > Thorsten Schöning > > -- > Thorsten Schöning E-Mail: thorsten.schoen...@am-soft.de > AM-SoFT IT-Systeme http://www.AM-SoFT.de/ > > Telefon...05151- 9468- 55 > Fax...05151- 9468- 88 > Mobil..0178-8 9468- 04 > > AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln > AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow > > > - > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > -- Become a Wicket expert, learn from the best: http://wicketinaction.com - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Question regarding index handling with RefreshingView and OddEvenItem
Hi, I know that I'm skirting around answering your questions, but you could add an AttributeAppender to the item based on the index. Something like item.add( AttributeAppender.modify( "class", item.getIndex() % 2 == 1 ? getEvenCssClass() : getOddCssClass() ); Apply further refactorings to suit your needs, i.e. introduce your own subclass of Behavior/AttributeModifier which provides the attribute appender functionality plus getEvenCssClass() and getOddCssClass(). This way, you can apply your even/odd styling to all you DataViews, and have your style information in one place. Plus you can use stock DataTable or ListView. Thorsten Schöning wrote: > Hi all, > > I'm using DataView to publish some search results in a HTML table and > what the results to format zebra style. I've found OddEvenItem for > that purpose but ran into what I find is a problem: The first item is > always rendered with CSS class "even", because the index used is 0 > based. That may be correct from a technical point of view, but is not > what I want to present my users. I kind of don't understand: you want to present a zebra table to your users, that is what you do. But what exactly do you want to achieve? First row is termed "odd" instead of "even"? Why would that matter? Can't you just flip your CSS classes if styling is your concern? > > So I changed my creation of OddEvenItem to simply not provide index 0, > but found that my provided index is always ignored. Even if I change > my index to a constant like 1 it is ignored. > > I found the problem in RefreshingView.addItems, where a loop is used > to iterate over items and an index is always set: > >> protected void addItems(Iterator> items) >> { >> int index = 0; >> while (items.hasNext()) >> { >> Item item = items.next(); >> item.setIndex(index); >> add(item); >> ++index; >> } >> } > > This doesn't make sense to me, because the OddEvenItem ctor is > designed to take an index, which is afterwards ignored. > > Two questions here: > > 1. Is the call to setIndex by design and one should override setIndex in > custom created items to just ignore that call? In that case the > documentation for Item should make that more clear, unless I have > missed that. I think the contract between DataTable and Item is Item#setIndex, not the constructor of the specialization OddEvenItem. I find it rather dangerous to modify the indexes by skipping zero etc. as this may change Wicket's internal bookkeeping of items. > > 2. How should I get my OddEvenItem to print CSS classes based on a 1 > index at all? Should I override onComponentTag instead of changing the > index to 1 in my newItem-method? > > Thanks für help! > > Mit freundlichen Grüßen, > > Thorsten Schöning > Hope this helps, bye Stefan - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Question regarding index handling with RefreshingView and OddEvenItem
Hi all, I'm using DataView to publish some search results in a HTML table and what the results to format zebra style. I've found OddEvenItem for that purpose but ran into what I find is a problem: The first item is always rendered with CSS class "even", because the index used is 0 based. That may be correct from a technical point of view, but is not what I want to present my users. So I changed my creation of OddEvenItem to simply not provide index 0, but found that my provided index is always ignored. Even if I change my index to a constant like 1 it is ignored. I found the problem in RefreshingView.addItems, where a loop is used to iterate over items and an index is always set: > protected void addItems(Iterator> items) > { > int index = 0; > while (items.hasNext()) > { > Item item = items.next(); > item.setIndex(index); > add(item); > ++index; > } > } This doesn't make sense to me, because the OddEvenItem ctor is designed to take an index, which is afterwards ignored. Two questions here: 1. Is the call to setIndex by design and one should override setIndex in custom created items to just ignore that call? In that case the documentation for Item should make that more clear, unless I have missed that. 2. How should I get my OddEvenItem to print CSS classes based on a 1 index at all? Should I override onComponentTag instead of changing the index to 1 in my newItem-method? Thanks für help! Mit freundlichen Grüßen, Thorsten Schöning -- Thorsten Schöning E-Mail: thorsten.schoen...@am-soft.de AM-SoFT IT-Systeme http://www.AM-SoFT.de/ Telefon...05151- 9468- 55 Fax...05151- 9468- 88 Mobil..0178-8 9468- 04 AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org