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<Item<T>> items)
>> {
>>       int index = 0;
>>       while (items.hasNext())
>>       {
>>               Item<T> 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

Reply via email to