0

I wanna make the items of list view, that is, table cells, clickable so that they will send to another page. Could anyone let me know what's my problem here ? Thanks in advance.

That's the html : http://pastebin.com/qUaPzTwv

That's what i'm trying

    Application app = (Application) getApplication();
    MovieCollection col = app.getCollection();
    List<Movie> movies = col.getMovies();

    add(new ListView("movie_list", movies) {

        @Override
        protected void populateItem(ListItem item) {
            final Movie movie = (Movie) item.getModelObject();
            item.add(new Label("title", movie.getTitle()));
            item.add(new Label("year", Integer.toString(movie.getYear())));
            item.add(new Link("movie_link") {

                @Override
                public void onClick() {
                    setResponsePage(new MoviePage(movie));
                }
            });
        }
    });

And that's the output :

Last cause: Unable to find component with id 'title' in [ [Component id = movie_link]]
Expected: 'movie_list:0:movie_link.title'.
Found with similar names: 'movie_list:0:title', movie_list:1:title', movie_list:2:title'
NotCamelCase
  • 1,073
  • 1
  • 10
  • 18

1 Answers1

3

As commented, this is happening because your hierarchy does not match between the html and java, meaning that if you have an element with a wicket:id who has children elements with wicket:id's, you must add the children to their parents. Ultimately this is how your page is working: the page is nothing more than a component with children, and this is how your ListView is working.

 add(new ListView("movie_list", movies) {

    @Override
    protected void populateItem(ListItem item) {
        final Movie movie = (Movie) item.getModelObject();
        Link link = new Link("movie_link") {

            @Override
            public void onClick() {
                setResponsePage(new MoviePage(movie));
            }
        };
        item.add(link);
        link.add(new Label("year", Integer.toString(movie.getYear())));
        link.add(new Label("year", Integer.toString(movie.getYear())));
    }
});

The error you are receiving provides you with the answer to your question. It gives you the component path which is a list of wicket:id's from the component back to the page. In this case it tells you that it expected "title" to be the child of "movie_link" but found it to be the child of the ListItem (the "0" represents the index of the ListView children... ListItems)

Daniel Semmens
  • 461
  • 2
  • 4
  • +1 for pointing out how to use the information in the exception to solve the problem. You gave OP a fishing rod as well as a fish. :) – biziclop Jun 16 '12 at 19:10