Now that we have our Pod in place we can add content to it. The PodBuilder class provides an addContent(...) method to add the content to a Pod. In our movies example we are going to delegate to the list widget which can generate a HTML table.
To start we will need to provide the movies for our list. Appendix A.1 contains a full program-listing for a Java class that will act as a simple read-only DB of our favourite movies. Add this class to a package in the project where it can be accessed by our PodLoader.
Next we will create a list in our PodLoader and populate it with our favourite movies. In the PodLoader add the following code to the createPod method before the return statement.
001 public Node createPod(Document document, Map<String,Object> contexts) { 002 try{ 003 PodBuilder moviesPod = 004 PodBuilder.newPod(document, PODTYPE.MYFAVMOVIES); 005 moviesPod.setTitle("My Favourite Movies"); 006 007 MoviesDB moviesDB = new MoviesDB(); 008 009 Collection<MoviesDB.Movie> favMovieCollection = 010 moviesDB.getAllMovies(); 011 Iterator<MoviesDB.Movie> movieList = 012 favMovieCollection.iterator(); 013 014 // Create the list 015 ListBuilder myFavouriteMovies = 016 ListBuilder.createList(1, document); 017 018 int row = 1; 019 while(movieList.hasNext()) { 020 Movie movie = movieList.next(); 021 String movieName = movie.title; 022 myFavouriteMovies.addRow(); 023 myFavouriteMovies.addEntry(1, row++, movieName); 024 } 025 026 RendererConfig contentRenderer = new RendererConfig( 027 RendererConfigType.STYLE, "single-list"); 028 moviesPod.addContent(myFavouriteMovies, contentRenderer); 029 030 return moviesPod.getWidgetRootNode(); 031 }catch(Exception e){ 032 throw new RuntimeException(e); 033 }
Compile your PodLoader class and reload the Pod page. The 'My Favourite Movies' Pod will be updated with the list of our favourite movies.
In the next section we will look in more detail at how the list was created.