listview.setReuseItems(true)

Martijn

On Wed, Jun 24, 2009 at 5:03 PM, Azzeddine Daddah<[email protected]> wrote:
> Thanks again Vasu,
>
> I've tried your solution but it does not work yet. Below my code:
>
> public TestPage() {
>        final WebMarkupContainer container = new
> WebMarkupContainer("container");
>        container.setOutputMarkupId(true);
>
>        container.add(new ListView<Category>("categories", buildCategories()) {
>           �...@override
>            protected void populateItem(ListItem<Category> item) {
>                Category category = item.getModelObject();
>                item.add(new Label("category", category.getName()));
>                item.add(new ListView<Topic>("topics", category.getTopics()) {
>                   �...@override
>                    protected void populateItem(final ListItem<Topic> item) {
>                        final Topic topic = item.getModelObject();
>                        final Label topicLabel = new Label("topic",
> topic.getName());
>                        item.add(new AjaxLink<String>("topicLink") {
>                           �...@override
>                            public void onClick(AjaxRequestTarget target) {
>                                item.add(topicLabel).add(new
> AttributeModifier("class", true, new AbstractReadOnlyModel<String>() {
>                                   �...@override
>                                    public String getObject() {
>                                        return "highlight";
>                                    }
>                                }));
>                                target.addComponent(container);
>                            }
>                        }.add(topicLabel));
>                    }
>                });
>            }
>        });
>        add(container);
>    }
>
> Any other suggestions?
>
>
> Regards,
> Hbiloo
>
>
> On Wed, Jun 24, 2009 at 3:48 PM, Vasu Srinivasan<[email protected]> wrote:
>> I see you are trying to add the class modifier to "item" which is ListItem
>> and thats not a HTML component.
>> In my case, I was adding it to the link or label. I think you may have to do
>> something like
>>
>> item.add(new Label(...).add(new AttributeModifier("class", new
>> AbstractReadOnlyModel() ...
>>
>> etc.
>>
>>
>> On Wed, Jun 24, 2009 at 7:28 AM, Azzeddine Daddah 
>> <[email protected]>wrote:
>>
>>> Thanks Vasu for your replay.
>>>
>>> I've tried your suggestion, but didn't work. This is what I get in the
>>> Ajax debuger when I click a certain item:
>>> ...
>>> <li>
>>>   <a id="topicLink31" href="#" onclick="var
>>>
>>> wcall=wicketAjaxGet('?wicket:interface=:0:container:categories:3:topics:3:topicLink::IBehaviorListener:0:-1',null,null,
>>> function() {return Wicket.$('topicLink31') !=
>>> null;}.bind(this));return !wcall;"><span>Yeeh</span></a>
>>> </li>
>>> ...
>>>
>>> Does someone else already got the same issue?
>>>
>>> Regards,
>>> Hbiloo
>>>
>>>
>>> On Wed, Jun 24, 2009 at 12:36 PM, Vasu Srinivasan<[email protected]>
>>> wrote:
>>> > Ive got a very similar thing working.
>>> >
>>> > I think you may have to return the "highlight" value dynamically. Try
>>> this
>>> > alternative:
>>> >
>>> > item.add(new AttributeModifier("class", true, new AbstractReadOnlyModel()
>>> {
>>> > �...@override public Object getObject() {
>>> >      return "highlight"
>>> >  }
>>> > });
>>> >
>>> > On Tue, Jun 23, 2009 at 5:56 PM, Azzeddine Daddah <[email protected]
>>> >wrote:
>>> >
>>> >> Hi Wicket users,
>>> >>
>>> >> I've a ListView in a ListView. The 1st ListVeiw holds "categories".
>>> >> The 2nd ListView holds links (topics) which I want to be highlighted
>>> >> if the link (topic) is clicked. The problem is that the wrapped list
>>> >> (container) is getting refreshed, but the CSS class is not set for the
>>> >> corresponding list item.
>>> >> Below my code:
>>> >>
>>> >> TestPage.java
>>> >> ========================================
>>> >> import java.io.Serializable;
>>> >> import java.util.ArrayList;
>>> >> import java.util.Arrays;
>>> >> import java.util.List;
>>> >>
>>> >> import org.apache.wicket.AttributeModifier;
>>> >> import org.apache.wicket.ajax.AjaxRequestTarget;
>>> >> import org.apache.wicket.ajax.markup.html.AjaxLink;
>>> >> import org.apache.wicket.markup.html.WebMarkupContainer;
>>> >> import org.apache.wicket.markup.html.basic.Label;
>>> >> import org.apache.wicket.markup.html.list.ListItem;
>>> >> import org.apache.wicket.markup.html.list.ListView;
>>> >> import org.apache.wicket.model.Model;
>>> >> import org.wicketstuff.annotation.mount.MountPath;
>>> >>
>>> >> import com.hbiloo.receptino.web.page.template.PageWithoutSideBar;
>>> >>
>>> >> @MountPath(path = "test")
>>> >> public class TestPage extends PageWithoutSideBar {
>>> >>
>>> >>       �...@suppresswarnings("serial")
>>> >>        public TestPage() {
>>> >>                final WebMarkupContainer container = new
>>> >> WebMarkupContainer("container");
>>> >>                container.setOutputMarkupId(true);
>>> >>
>>> >>                container.add(new ListView<Category>("categories",
>>> >> buildCategories()) {
>>> >>                       �...@override
>>> >>                        protected void populateItem(ListItem<Category>
>>> item)
>>> >> {
>>> >>                                Category category =
>>> item.getModelObject();
>>> >>                                item.add(new Label("category",
>>> >> category.getName()));
>>> >>                                item.add(new ListView<Topic>("topics",
>>> >> category.getTopics()) {
>>> >>                                       �...@override
>>> >>                                        protected void populateItem(final
>>> >> ListItem<Topic> item) {
>>> >>                                                Topic topic =
>>> >> item.getModelObject();
>>> >>                                                AjaxLink<String>
>>> topicLink =
>>> >> (new AjaxLink<String>("topicLink") {
>>> >>                                                       �...@override
>>> >>                                                        public void
>>> >> onClick(AjaxRequestTarget target) {
>>> >>
>>> >>  target.addComponent(container);
>>> >>
>>>  item.add(new
>>> >> AttributeModifier("class", true, new
>>> >> Model<String>("highlight")));
>>> >>                                                        }
>>> >>                                                });
>>> >>                                                topicLink.add(new
>>> >> Label("topic", topic.getName()));
>>> >>                                                item.add(topicLink);
>>> >>                                        }
>>> >>                                });
>>> >>                        }
>>> >>                });
>>> >>                add(container);
>>> >>        }
>>> >>
>>> >>       �...@suppresswarnings("serial")
>>> >>        private class Category implements Serializable {
>>> >>                private String name;
>>> >>                private List<Topic> topics;
>>> >>
>>> >>                public Category(String name, List<Topic> topics) {
>>> >>                        this.name = name;
>>> >>                        this.topics = topics;
>>> >>                }
>>> >>
>>> >>                public String getName() {
>>> >>                        return name;
>>> >>                }
>>> >>
>>> >>                public List<Topic> getTopics() {
>>> >>                        return topics;
>>> >>                }
>>> >>        }
>>> >>
>>> >>       �...@suppresswarnings("serial")
>>> >>        private class Topic implements Serializable {
>>> >>                private String name;
>>> >>
>>> >>                public Topic(String name) {
>>> >>                        this.name = name;
>>> >>                }
>>> >>
>>> >>                public String getName() {
>>> >>                        return name;
>>> >>                }
>>> >>        }
>>> >>
>>> >>        private List<Category> buildCategories() {
>>> >>                List<Category> categories = new ArrayList<Category>();
>>> >>                categories.add(new Category("Movies", Arrays.asList(new
>>> >> Topic("Mamma"),
>>> >>                                new Topic("USA"), new Topic("NL"))));
>>> >>                categories.add(new Category("Articles", Arrays.asList(
>>> >>                                new Topic("Test"), new
>>> >> Topic("Nederland"))));
>>> >>                categories.add(new Category("Images", Arrays.asList(new
>>> >> Topic("Mag"),
>>> >>                                new Topic("Spullen"), new Topic("Mamma
>>> >> mia"))));
>>> >>                categories.add(new Category("Links", Arrays.asList(new
>>> >> Topic("Ana"),
>>> >>                                new Topic("Smiti"), new Topic("Hbiloo"),
>>> new
>>> >> Topic("Yeeh"))));
>>> >>                return categories;
>>> >>        }
>>> >> }
>>> >>
>>> >> TestPage.html
>>> >> ========================================
>>> >> <html xmlns:wicket>
>>> >>    <wicket:extend>
>>> >>    <ul class="menu" wicket:id="container">
>>> >>        <li class="r" wicket:id="categories"><span class="category"
>>> >>            wicket:id="category">Category A: </span>
>>> >>        <ul>
>>> >>            <li wicket:id="topics"><a wicket:id="topicLink"><span
>>> >>                wicket:id="topic">Link</span></a></li>
>>> >>        </ul>
>>> >>        </li>
>>> >>    </ul>
>>> >> </wicket:extend>
>>> >> </html>
>>> >>
>>> >> Kind regards,
>>> >>
>>> >> Hbiloo
>>> >>
>>> >> ---------------------------------------------------------------------
>>> >> To unsubscribe, e-mail: [email protected]
>>> >> For additional commands, e-mail: [email protected]
>>> >>
>>> >>
>>> >
>>> >
>>> > --
>>> > Regards,
>>> > Vasu Srinivasan
>>> >
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [email protected]
>>> For additional commands, e-mail: [email protected]
>>>
>>>
>>
>>
>> --
>> Regards,
>> Vasu Srinivasan
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>



-- 
Become a Wicket expert, learn from the best: http://wicketinaction.com
Apache Wicket 1.3.5 is released
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to