You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Arnaud Garcia <ar...@imagemed-87.com> on 2010/03/28 16:40:49 UTC

change background color when ListView iterate....

Hello,

Using a ListView on a <tr> html markup, I would like to alternate the
background color of each "new" tr when the list iterate...

I just find how to do this on the label inside the td... not on the <tr>
level..., so just the background color of the title is changed and not the
full line !

here is an example of my code....

html:
--------

<table>
    <tr wicket:id="cdList">
       <td><span wicket:id="title"/></td>
    </tr>
</table>


java:
------
ListView<CD> aList = new ListView<CD>("cdList",CDList) {

         private boolean alternateLine = true; // to switch css class
attribute at each new item...

         @Override
         protected void populateItem(ListItem<CD> item) {

             Label title = new Label("title", new
PropertyModel<String>(item.getModelObject(), "title"));

             if (alternateLine) {
                 title.add(new SimpleAttributeModifier("class", "line1"));
// change the color !
             } else {
                 title.add(new SimpleAttributeModifier("class", "line2"));
             }
             alternateLine = !alternateLine;

             item.add(title)
            }
}


thanks,

Arnaud

Re: change background color when ListView iterate....

Posted by Bustanil Arifin <st...@gmail.com>.
Using ListItem#newItem(final int index) should be suffice.
The item is the <tr> element. I tried it like this:

...
            protected ListItem<MyModel> newItem(int index) {
                ListItem<MyModel> item = super.newItem(index);
                item.add(new SimpleAttributeModifier("class", index %
2 == 0? "even" : "odd"));
                return item;
            }
...

On Mon, Mar 29, 2010 at 9:24 AM, Arnaud Garcia <ar...@imagemed-87.com> wrote:
> Hi,
>
> Defenitively it is more elegant to use the "OddEvenItem" object instead of
> using my boolean... but it doesn't change my problem...
> Changing the class of the items can be done easily (see my code, or you can
> use OddEventItem etc..) But the problem is to change the class at the upper
> level in the <tr> ?
>
> I am certainely not clear, so I can reformulate like this: how can you
> create a table where lines are blue then white and so on when you iterate
> over a ListView...
>
> thanks for help,
>
> Arnaud
>
>
> 2010/3/28 Mauro Ciancio <ma...@gmail.com>
>
>> Take a look at:
>>
>> ListItem#newItem(final int index)
>>
>> and:
>>
>> org.apache.wicket.markup.repeater.OddEvenItem.
>>
>> Cheers.
>>
>> On Sun, Mar 28, 2010 at 11:40 AM, Arnaud Garcia <ar...@imagemed-87.com>
>> wrote:
>> > Hello,
>> >
>> > Using a ListView on a <tr> html markup, I would like to alternate the
>> > background color of each "new" tr when the list iterate...
>> >
>> > I just find how to do this on the label inside the td... not on the <tr>
>> > level..., so just the background color of the title is changed and not
>> the
>> > full line !
>> >
>> > here is an example of my code....
>> >
>> > html:
>> > --------
>> >
>> > <table>
>> >    <tr wicket:id="cdList">
>> >       <td><span wicket:id="title"/></td>
>> >    </tr>
>> > </table>
>> >
>> >
>> > java:
>> > ------
>> > ListView<CD> aList = new ListView<CD>("cdList",CDList) {
>> >
>> >         private boolean alternateLine = true; // to switch css class
>> > attribute at each new item...
>> >
>> >         @Override
>> >         protected void populateItem(ListItem<CD> item) {
>> >
>> >             Label title = new Label("title", new
>> > PropertyModel<String>(item.getModelObject(), "title"));
>> >
>> >             if (alternateLine) {
>> >                 title.add(new SimpleAttributeModifier("class", "line1"));
>> > // change the color !
>> >             } else {
>> >                 title.add(new SimpleAttributeModifier("class", "line2"));
>> >             }
>> >             alternateLine = !alternateLine;
>> >
>> >             item.add(title)
>> >            }
>> > }
>> >
>> >
>> > thanks,
>> >
>> > Arnaud
>> >
>>
>>
>>
>> --
>> Mauro Ciancio <maurociancio at gmail dot com>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>



-- 
Bustanil Arifin
"Keep moving forward!"

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: change background color when ListView iterate....

Posted by Arnaud Garcia <ar...@imagemed-87.com>.
Grrr, I had the SimpleAttribute to the Label of my Item not to my item
directly ...
I didn't know that the item was attached to the tr...

thanks for help !!!!

Arnaud

2010/3/29 Martijn Dashorst <ma...@gmail.com>

> each list item is attached to the tr tag. Therefore the OddEvenItem
> solution just works. Did you try it?
>
> Martijn
>
> On Mon, Mar 29, 2010 at 9:24 AM, Arnaud Garcia <ar...@imagemed-87.com>
> wrote:
> > Hi,
> >
> > Defenitively it is more elegant to use the "OddEvenItem" object instead
> of
> > using my boolean... but it doesn't change my problem...
> > Changing the class of the items can be done easily (see my code, or you
> can
> > use OddEventItem etc..) But the problem is to change the class at the
> upper
> > level in the <tr> ?
> >
> > I am certainely not clear, so I can reformulate like this: how can you
> > create a table where lines are blue then white and so on when you iterate
> > over a ListView...
> >
> > thanks for help,
> >
> > Arnaud
> >
> >
> > 2010/3/28 Mauro Ciancio <ma...@gmail.com>
> >
> >> Take a look at:
> >>
> >> ListItem#newItem(final int index)
> >>
> >> and:
> >>
> >> org.apache.wicket.markup.repeater.OddEvenItem.
> >>
> >> Cheers.
> >>
> >> On Sun, Mar 28, 2010 at 11:40 AM, Arnaud Garcia <arnaud@imagemed-87.com
> >
> >> wrote:
> >> > Hello,
> >> >
> >> > Using a ListView on a <tr> html markup, I would like to alternate the
> >> > background color of each "new" tr when the list iterate...
> >> >
> >> > I just find how to do this on the label inside the td... not on the
> <tr>
> >> > level..., so just the background color of the title is changed and not
> >> the
> >> > full line !
> >> >
> >> > here is an example of my code....
> >> >
> >> > html:
> >> > --------
> >> >
> >> > <table>
> >> >    <tr wicket:id="cdList">
> >> >       <td><span wicket:id="title"/></td>
> >> >    </tr>
> >> > </table>
> >> >
> >> >
> >> > java:
> >> > ------
> >> > ListView<CD> aList = new ListView<CD>("cdList",CDList) {
> >> >
> >> >         private boolean alternateLine = true; // to switch css class
> >> > attribute at each new item...
> >> >
> >> >         @Override
> >> >         protected void populateItem(ListItem<CD> item) {
> >> >
> >> >             Label title = new Label("title", new
> >> > PropertyModel<String>(item.getModelObject(), "title"));
> >> >
> >> >             if (alternateLine) {
> >> >                 title.add(new SimpleAttributeModifier("class",
> "line1"));
> >> > // change the color !
> >> >             } else {
> >> >                 title.add(new SimpleAttributeModifier("class",
> "line2"));
> >> >             }
> >> >             alternateLine = !alternateLine;
> >> >
> >> >             item.add(title)
> >> >            }
> >> > }
> >> >
> >> >
> >> > thanks,
> >> >
> >> > Arnaud
> >> >
> >>
> >>
> >>
> >> --
> >> Mauro Ciancio <maurociancio at gmail dot com>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> For additional commands, e-mail: users-help@wicket.apache.org
> >>
> >>
> >
>
>
>
> --
> Become a Wicket expert, learn from the best: http://wicketinaction.com
> Apache Wicket 1.4 increases type safety for web applications
> Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.4.4
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: change background color when ListView iterate....

Posted by Martijn Dashorst <ma...@gmail.com>.
each list item is attached to the tr tag. Therefore the OddEvenItem
solution just works. Did you try it?

Martijn

On Mon, Mar 29, 2010 at 9:24 AM, Arnaud Garcia <ar...@imagemed-87.com> wrote:
> Hi,
>
> Defenitively it is more elegant to use the "OddEvenItem" object instead of
> using my boolean... but it doesn't change my problem...
> Changing the class of the items can be done easily (see my code, or you can
> use OddEventItem etc..) But the problem is to change the class at the upper
> level in the <tr> ?
>
> I am certainely not clear, so I can reformulate like this: how can you
> create a table where lines are blue then white and so on when you iterate
> over a ListView...
>
> thanks for help,
>
> Arnaud
>
>
> 2010/3/28 Mauro Ciancio <ma...@gmail.com>
>
>> Take a look at:
>>
>> ListItem#newItem(final int index)
>>
>> and:
>>
>> org.apache.wicket.markup.repeater.OddEvenItem.
>>
>> Cheers.
>>
>> On Sun, Mar 28, 2010 at 11:40 AM, Arnaud Garcia <ar...@imagemed-87.com>
>> wrote:
>> > Hello,
>> >
>> > Using a ListView on a <tr> html markup, I would like to alternate the
>> > background color of each "new" tr when the list iterate...
>> >
>> > I just find how to do this on the label inside the td... not on the <tr>
>> > level..., so just the background color of the title is changed and not
>> the
>> > full line !
>> >
>> > here is an example of my code....
>> >
>> > html:
>> > --------
>> >
>> > <table>
>> >    <tr wicket:id="cdList">
>> >       <td><span wicket:id="title"/></td>
>> >    </tr>
>> > </table>
>> >
>> >
>> > java:
>> > ------
>> > ListView<CD> aList = new ListView<CD>("cdList",CDList) {
>> >
>> >         private boolean alternateLine = true; // to switch css class
>> > attribute at each new item...
>> >
>> >         @Override
>> >         protected void populateItem(ListItem<CD> item) {
>> >
>> >             Label title = new Label("title", new
>> > PropertyModel<String>(item.getModelObject(), "title"));
>> >
>> >             if (alternateLine) {
>> >                 title.add(new SimpleAttributeModifier("class", "line1"));
>> > // change the color !
>> >             } else {
>> >                 title.add(new SimpleAttributeModifier("class", "line2"));
>> >             }
>> >             alternateLine = !alternateLine;
>> >
>> >             item.add(title)
>> >            }
>> > }
>> >
>> >
>> > thanks,
>> >
>> > Arnaud
>> >
>>
>>
>>
>> --
>> Mauro Ciancio <maurociancio at gmail dot com>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>



-- 
Become a Wicket expert, learn from the best: http://wicketinaction.com
Apache Wicket 1.4 increases type safety for web applications
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.4.4

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: change background color when ListView iterate....

Posted by Arnaud Garcia <ar...@imagemed-87.com>.
Hi,

Defenitively it is more elegant to use the "OddEvenItem" object instead of
using my boolean... but it doesn't change my problem...
Changing the class of the items can be done easily (see my code, or you can
use OddEventItem etc..) But the problem is to change the class at the upper
level in the <tr> ?

I am certainely not clear, so I can reformulate like this: how can you
create a table where lines are blue then white and so on when you iterate
over a ListView...

thanks for help,

Arnaud


2010/3/28 Mauro Ciancio <ma...@gmail.com>

> Take a look at:
>
> ListItem#newItem(final int index)
>
> and:
>
> org.apache.wicket.markup.repeater.OddEvenItem.
>
> Cheers.
>
> On Sun, Mar 28, 2010 at 11:40 AM, Arnaud Garcia <ar...@imagemed-87.com>
> wrote:
> > Hello,
> >
> > Using a ListView on a <tr> html markup, I would like to alternate the
> > background color of each "new" tr when the list iterate...
> >
> > I just find how to do this on the label inside the td... not on the <tr>
> > level..., so just the background color of the title is changed and not
> the
> > full line !
> >
> > here is an example of my code....
> >
> > html:
> > --------
> >
> > <table>
> >    <tr wicket:id="cdList">
> >       <td><span wicket:id="title"/></td>
> >    </tr>
> > </table>
> >
> >
> > java:
> > ------
> > ListView<CD> aList = new ListView<CD>("cdList",CDList) {
> >
> >         private boolean alternateLine = true; // to switch css class
> > attribute at each new item...
> >
> >         @Override
> >         protected void populateItem(ListItem<CD> item) {
> >
> >             Label title = new Label("title", new
> > PropertyModel<String>(item.getModelObject(), "title"));
> >
> >             if (alternateLine) {
> >                 title.add(new SimpleAttributeModifier("class", "line1"));
> > // change the color !
> >             } else {
> >                 title.add(new SimpleAttributeModifier("class", "line2"));
> >             }
> >             alternateLine = !alternateLine;
> >
> >             item.add(title)
> >            }
> > }
> >
> >
> > thanks,
> >
> > Arnaud
> >
>
>
>
> --
> Mauro Ciancio <maurociancio at gmail dot com>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: change background color when ListView iterate....

Posted by Mauro Ciancio <ma...@gmail.com>.
Take a look at:

ListItem#newItem(final int index)

and:

org.apache.wicket.markup.repeater.OddEvenItem.

Cheers.

On Sun, Mar 28, 2010 at 11:40 AM, Arnaud Garcia <ar...@imagemed-87.com> wrote:
> Hello,
>
> Using a ListView on a <tr> html markup, I would like to alternate the
> background color of each "new" tr when the list iterate...
>
> I just find how to do this on the label inside the td... not on the <tr>
> level..., so just the background color of the title is changed and not the
> full line !
>
> here is an example of my code....
>
> html:
> --------
>
> <table>
>    <tr wicket:id="cdList">
>       <td><span wicket:id="title"/></td>
>    </tr>
> </table>
>
>
> java:
> ------
> ListView<CD> aList = new ListView<CD>("cdList",CDList) {
>
>         private boolean alternateLine = true; // to switch css class
> attribute at each new item...
>
>         @Override
>         protected void populateItem(ListItem<CD> item) {
>
>             Label title = new Label("title", new
> PropertyModel<String>(item.getModelObject(), "title"));
>
>             if (alternateLine) {
>                 title.add(new SimpleAttributeModifier("class", "line1"));
> // change the color !
>             } else {
>                 title.add(new SimpleAttributeModifier("class", "line2"));
>             }
>             alternateLine = !alternateLine;
>
>             item.add(title)
>            }
> }
>
>
> thanks,
>
> Arnaud
>



-- 
Mauro Ciancio <maurociancio at gmail dot com>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org