Use better way to paginate the posts.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 1 Apr 2011 20:51:05 +0000 (22:51 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 1 Apr 2011 20:51:05 +0000 (22:51 +0200)
src/main/java/net/pterodactylus/sone/web/ViewSonePage.java
src/main/resources/templates/viewSone.html

index 3f4d92d..cd79e43 100644 (file)
@@ -65,6 +65,10 @@ public class ViewSonePage extends SoneTemplatePage {
                String soneId = request.getHttpRequest().getParam("sone");
                Sone sone = webInterface.getCore().getSone(soneId, false);
                templateContext.set("sone", sone);
+               List<Post> sonePosts = sone.getPosts();
+               Pagination<Post> postPagination = new Pagination<Post>(sonePosts, 10).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("postPage"), 0));
+               templateContext.set("postPagination", postPagination);
+               templateContext.set("posts", postPagination.getItems());
                Set<Reply> replies = sone.getReplies();
                final Map<Post, List<Reply>> repliedPosts = new HashMap<Post, List<Reply>>();
                for (Reply reply : replies) {
@@ -100,7 +104,7 @@ public class ViewSonePage extends SoneTemplatePage {
                        return;
                }
                webInterface.getCore().markSoneKnown(sone);
-               List<Post> posts = sone.getPosts();
+               List<Post> posts = (List<Post>) templateContext.get("posts");
                posts.addAll((List<Post>) templateContext.get("repliedPosts"));
                for (Post post : posts) {
                        if (post.getSone() != null) {
index 830b999..066adef 100644 (file)
 
                <h1><%= Page.ViewSone.PostList.Title|l10n|replace needle="{sone}" replacementKey=sone.niceName|html></h1>
 
-               <div id="posts">
-                       <%:getpage parameter=postPage>
-                       <%:paginate list=sone.posts pagesize=10>
-                       <%= postPage|store key=pageParameter>
-                       <%include include/pagination.html>
-                       <%foreach pagination.items post>
-                               <%include include/viewPost.html>
-                       <%foreachelse>
-                               <div><%= Page.ViewSone.PostList.Text.NoPostYet|l10n|html></div>
-                       <%/foreach>
-                       <%include include/pagination.html>
-               </div>
+               <%foreach posts post>
+                       <%first>
+                               <div id="posts">
+                                       <%include include/pagination.html pagination=postPagination pageParameter==postPage>
+                       <%/first>
+                       <%include include/viewPost.html>
+                       <%last>
+                                       <%include include/pagination.html pagination=postPagination pageParameter==postPage>
+                               </div>
+                       <%/last>
+               <%foreachelse>
+                       <div><%= Page.ViewSone.PostList.Text.NoPostYet|l10n|html></div>
+               <%/foreach>
 
                <%foreach repliedPosts post>
                        <%first>