|
From: <jbo...@li...> - 2006-06-22 01:09:58
|
Author: unibrew
Date: 2006-06-21 21:09:52 -0400 (Wed, 21 Jun 2006)
New Revision: 4802
Modified:
labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/ModeratorAction.java
labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/moderator/modcp_body.xhtml
labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/moderator/modcp_move.xhtml
Log:
[JBFORUMS-44] Working on pagination.
Modified: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/ModeratorAction.java
===================================================================
--- labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/ModeratorAction.java 2006-06-21 22:39:43 UTC (rev 4801)
+++ labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/ModeratorAction.java 2006-06-22 01:09:52 UTC (rev 4802)
@@ -22,6 +22,8 @@
package org.jboss.portlet.forums.ui.action;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -44,6 +46,7 @@
import org.jboss.portlet.forums.ui.Constants;
import org.jboss.portlet.forums.ui.ForumUtil;
import org.jboss.portlet.forums.ui.JSFUtil;
+import org.jboss.portlet.forums.ui.view.PageNavigator;
/**
* @author <a href="mailto:rys...@jb...">Ryszard Kozmik</a>
@@ -51,75 +54,75 @@
public class ModeratorAction extends BaseController
{
+ //preference related data
+ private PreferenceController userPreferences = null;
+
//business data being generated in this bean by executing ui actions
//this is data is created such that it can be consumed by the view components
//like facelets
private Forum forum = null;
-
+ private PageNavigator pageNavigator = null;
+ private Collection page = new ArrayList();
+ private Map topicNavigator = new HashMap();
private Map checkboxes;
private ResourceBundle bundle;
- //----------------bean configuration supplied by the forums-config.xml---------------------------------------------------------------------------------------------
+ // Page navigation methods
+ /**
+ *
+ */
+ public PageNavigator getPageNavigator()
+ {
+ return this.pageNavigator;
+ }
+
+ /**
+ *
+ *
+ */
+ public Map getTopicNavigator()
+ {
+ return this.topicNavigator;
+ }
+
+ //------------user preferences-------------------------------------------------------------------------------------------------------------
+ /**
+ * @return Returns the userPreferences.
+ */
+ public PreferenceController getUserPreferences()
+ {
+ return userPreferences;
+ }
+ /**
+ * @param userPreferences The userPreferences to set.
+ */
+ public void setUserPreferences(PreferenceController userPreferences)
+ {
+ this.userPreferences = userPreferences;
+ }
+ //-------------------------------------------------------------------------------------------------------------------------------------
-
//----------------business data being generated for use by the view components like facelets---------------------------------------------------------------------------------------
public Forum getForum()
{
return this.forum;
}
- public String getPagination()
- {
- /**
- * TODO: implement real code to get the pagination...
- */
- //stub code
- return "10";
- }
- public String getPageNumber()
- {
- /**
- * TODO: implement real code to get the pageNumber...
- */
- //stub code
- return "2";
- }
-
public void setCheckboxes(Map checkboxes)
{
this.checkboxes = checkboxes;
- Iterator it = checkboxes.keySet().iterator();
- System.out.println("test");
- while (it.hasNext())
- {
- String temp = (String)it.next();
- System.out.println("KEY: "+temp+" VALUE:"+checkboxes.get(temp));
- }
}
public Map getCheckboxes()
{
- try {
- if (checkboxes!=null) {
- Iterator it = checkboxes.keySet().iterator();
- System.out.println("GETCHECKBOXES FULL");
- while (it.hasNext())
- {
- Integer temp = (Integer)it.next();
- System.out.println("KEY: "+temp+" VALUE:"+checkboxes.get(temp));
- }
- } else
- {
- System.out.println("GETCHECKBOXES: EMPTY");
- }
- } catch (Exception e)
- {
- e.printStackTrace();
- }
return checkboxes;
}
+ public Collection getPage() {
+ return page;
+ }
+
//------------user preferences-------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------------
@@ -130,14 +133,6 @@
public ModeratorAction()
{
super();
- try
- {
- this.execute();
- }
- catch(Exception e)
- {
- JSFUtil.handleException(e);
- }
}
//ui actions supported by this bean----------------------------------------------------------------------------------------------------
@@ -185,16 +180,19 @@
String forum_to_id = ForumUtil.getParameter(Constants.p_forum_to_id);
if (forum_to_id==null || forum_to_id.trim().compareToIgnoreCase("-1")==0)
{
+ System.out.println("HELLO WORLD2");
message = bundle.getString("ERR_NO_DEST_FORUM");
FacesContext.getCurrentInstance().addMessage("message",
new FacesMessage(FacesMessage.SEVERITY_ERROR,message,"moderate"));
return "success";
}
-
+ Forum forumDest=null;
try {
- Forum forum = this.getForumsModule().findForumById(new Integer(forum_to_id));
+ forumDest = this.getForumsModule().findForumById(new Integer(forum_to_id));
+ System.out.println("HELLO WORLD3");
} catch (Exception e)
{
+ System.out.println("HELLO WORL4");
message = bundle.getString("ERR_INTERNAL");
FacesContext.getCurrentInstance().addMessage("message",
new FacesMessage(FacesMessage.SEVERITY_ERROR,message,"moderate"));
@@ -210,6 +208,7 @@
{
Topic topic = null;
try {
+ System.out.println("HELLO WORLD5");
topic = getForumsModule().findTopicById(topicId);
} catch(Exception e)
{
@@ -218,13 +217,14 @@
new FacesMessage(FacesMessage.SEVERITY_ERROR,message,"moderate"));
return "success";
}
- forum.addTopic(topic);
+ System.out.println("HELLO WORLD6");
+ forumDest.addTopic(topic);
}
}
message = bundle.getString("SUCC_TOPIC_MOVED");
FacesContext.getCurrentInstance().addMessage("message",
new FacesMessage(FacesMessage.SEVERITY_INFO,message, "moderate"));
- this.forum = BaseController.getForumsModule().findForumById(forum.getId());
+ this.forum = BaseController.getForumsModule().findForumById(this.forum.getId());
checkboxes=new HashMap();
} catch (Exception e)
{
@@ -365,6 +365,25 @@
return false;
}
+ /**
+ *
+ */
+ public boolean isInitialized()
+ {
+ boolean initialized = false;
+ try
+ {
+ this.execute();
+ initialized = true;
+ }
+ catch(Exception e)
+ {
+ JSFUtil.handleException(e);
+ }
+ System.out.println ("INITIALIZED: "+initialized);
+ return initialized;
+ }
+
private void execute() throws Exception
{
// Getting ResourceBundle with current Locale
@@ -374,19 +393,44 @@
ClassLoader ldr = Thread.currentThread().getContextClassLoader();
this.bundle = ResourceBundle.getBundle("ResourceJSF", locale, ldr);
+
+ int currentPage = 0;
+ //parse the input parameters
+ String pageParam = ForumUtil.getParameter(Constants.p_page);
+ if(pageParam!=null && pageParam.trim().length()>0)
+ {
+ //setup the page data
+ currentPage = Integer.parseInt(pageParam);
+ }
+
int forumId = -1;
String f = ForumUtil.getParameter(Constants.p_forumId);
+
if(f!=null && f.trim().length()>0)
{
forumId = Integer.parseInt(f);
}
- System.out.println("FORUMID: "+forumId);
+
+ //grab the data to be displayed for this page
if(forumId!=-1)
{
- // start with a stub implementation
+ //setup the business objects like the forum, topics etc that will be displayed
this.forum = BaseController.getForumsModule().findForumById(new Integer(forumId));
+ Object[] topicObjects = this.forum.getTopics().toArray();
checkboxes=new HashMap();
- }
+ System.out.println("TOPIC OBJ: "+topicObjects);
+ System.out.println("USER PREF: "+Integer.parseInt(this.userPreferences.getPreference(Constants.TOPICS_FORUM_KEY)));
+ System.out.println("CurrPage: "+currentPage);
+ //setup the pageNavigator for this forum
+ this.pageNavigator = new PageNavigator(
+ topicObjects, //total number of entries to be split up into pages
+ Integer.parseInt(this.userPreferences.getPreference(Constants.TOPICS_FORUM_KEY)),
+ currentPage //currently selected page being displayed, first page by default
+ );
+
+ this.page = this.pageNavigator.getPage();
+
+ }
}
Modified: labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/moderator/modcp_body.xhtml
===================================================================
--- labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/moderator/modcp_body.xhtml 2006-06-21 22:39:43 UTC (rev 4801)
+++ labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/moderator/modcp_body.xhtml 2006-06-22 01:09:52 UTC (rev 4802)
@@ -22,122 +22,210 @@
*/
-->
-<div xmlns="http://www.w3.org/1999/xhtml"
- xmlns:ui="http://java.sun.com/jsf/facelets"
- xmlns:c="http://java.sun.com/jstl/core"
- xmlns:h="http://java.sun.com/jsf/html"
- xmlns:f="http://java.sun.com/jsf/core"
- xmlns:forums="http://www.jboss.com/products/jbossportal/forums"
- class="bb"
->
+
+<div xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:ui="http://java.sun.com/jsf/facelets"
+ xmlns:c="http://java.sun.com/jstl/core"
+ xmlns:h="http://java.sun.com/jsf/html"
+ xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:forums="http://www.jboss.com/products/jbossportal/forums" class="bb">
<ui:composition template="/views/common/common.xhtml">
<ui:define name="mainContent">
-
-<h:messages layout="table" infoStyle="color:green" warnStyle="color:red" />
-
-<h:form>
- <table width="100%" cellspacing="2" cellpadding="2" border="0" align="center">
- <tr>
- <td align="left">
- <span class="nav">
- <a href="" class="nav"></a> ->
- <h:outputLink value="#{forums:outputLink(shared.links['forum'],true)}" styleClass="nav">
- <f:param name="f" value="#{moderator.forum.id}"/>
- <h:outputText value="#{moderator.forum.name}"/>
+<c:choose>
+ <c:when test="#{moderator.initialized && moderator.forum!=null && moderator.forum.id!=-1}">
+ <h:messages layout="table" infoStyle="color:green"
+ warnStyle="color:red"/>
+ <h:form>
+ <table width="100%" cellspacing="2" cellpadding="2" border="0"
+ align="center">
+ <tr>
+ <td align="left">
+ <span class="nav">
+ ->
+ <h:outputLink value="#{forums:outputLink(shared.links['forum'],true)}"
+ styleClass="nav">
+ <f:param name="f" value="#{moderator.forum.id}"/>
+ <h:outputText value="#{moderator.forum.name}"/>
</h:outputLink>
- </span>
- </td>
- </tr>
- </table>
-
- <table width="100%" cellpadding="4" cellspacing="1" border="0" class="forumline">
- <tr>
- <td class="catHead" colspan="5" align="center" height="28">
- <span class="cattitle">${resource.Mod_CP}</span>
- </td>
- </tr>
- <tr>
- <td class="spaceRow" colspan="5" align="center">
- <span class="gensmall">${resource.Mod_CP_explain}</span>
- </td>
- </tr>
- <tr>
- <th width="4%" class="thLeft" nowrap="nowrap">&nbsp;</th>
- <th nowrap="nowrap">&nbsp;${resource.Topics}&nbsp;</th>
- <th width="8%" nowrap="nowrap">&nbsp;${resource.Replies}&nbsp;</th>
- <th width="17%" nowrap="nowrap">&nbsp;${resource.Last_Post}&nbsp;</th>
- <th width="5%" class="thRight" nowrap="nowrap">&nbsp;${resource.Select}&nbsp;</th>
- </tr>
- <c:forEach items="#{moderator.forum.topics}" var="topicrow" >
- <tr>
- <td class="row1" align="center" valign="middle">
- <img src="#{forums:folderTypeURL(topicrow,moderator.anonymous)}"
- width="19"
- height="18"
+ </span>
+ </td>
+ </tr>
+ <tr>
+ <!-- page navigation -->
+ <c:if test="#{moderator.pageNavigator.totalPages gt 1}">
+ <td align="right" valign="middle" nowrap="nowrap">
+ <br/>
+ <span class="nav">
+ Goto page
+ <!-- previous link -->
+ <c:if test="#{moderator.pageNavigator.pageNumber gt 1}">
+ &nbsp;&nbsp;
+ <h:outputLink value="#{forums:outputLink(shared.links['moderator'],true)}">
+ <f:param name="f" value="#{moderator.forum.id}"/>
+ <f:param name="page"
+ value="#{moderator.pageNavigator.currentPage-1}"/>
+ <h:outputText value="Previous"/>
+ </h:outputLink>
+ &nbsp;&nbsp;
+ </c:if>
+ <!-- actual pages -->
+ <c:forEach items="#{moderator.pageNavigator.pages}"
+ var="page" varStatus="idx">
+ <c:choose>
+ <c:when test="#{moderator.pageNavigator.pageNumber==page}">
+ <b>${page}</b>
+ </c:when>
+ <c:otherwise>
+ <h:outputLink value="#{forums:outputLink(shared.links['moderator'],true)}">
+ <f:param name="f"
+ value="#{moderator.forum.id}"/>
+ <f:param name="page" value="#{page-1}"/>
+ <h:outputText value="${page}"/>
+ </h:outputLink>
+ </c:otherwise>
+ </c:choose>
+ <c:if test="${idx.index-1 ne moderator.pageNavigator.totalPages-1}">
+ <f:verbatim>,</f:verbatim>
+ </c:if>
+ </c:forEach>
+ <!-- Next link -->
+ <c:if test="#{moderator.pageNavigator.pageNumber lt moderator.pageNavigator.totalPages}">
+ &nbsp;&nbsp;
+ <h:outputLink value="#{forums:outputLink(shared.links['moderator'],true)}">
+ <f:param name="f" value="#{moderator.forum.id}"/>
+ <f:param name="page"
+ value="#{moderator.pageNavigator.currentPage+1}"/>
+ <h:outputText value="Next"/>
+ </h:outputLink>
+ &nbsp;&nbsp;
+ </c:if>
+ </span>
+ </td>
+ </c:if>
+ </tr>
+ </table>
+ <table width="100%" cellpadding="4" cellspacing="1" border="0"
+ class="forumline">
+ <tr>
+ <td class="catHead" colspan="5" align="center" height="28">
+ <span class="cattitle">${resource.Mod_CP}</span>
+ </td>
+ </tr>
+ <tr>
+ <td class="spaceRow" colspan="5" align="center">
+ <span class="gensmall">${resource.Mod_CP_explain}</span>
+ </td>
+ </tr>
+ <tr>
+ <th width="4%" class="thLeft" nowrap="nowrap">&nbsp;</th>
+ <th nowrap="nowrap">&nbsp;${resource.Topics}&nbsp;</th>
+ <th width="8%" nowrap="nowrap">&nbsp;${resource.Replies}&nbsp;</th>
+ <th width="17%" nowrap="nowrap">&nbsp;${resource.Last_Post}&nbsp;</th>
+ <th width="5%" class="thRight" nowrap="nowrap">&nbsp;${resource.Select}&nbsp;</th>
+ </tr>
+ <c:forEach items="#{moderator.page}" var="topicrow">
+ <tr>
+ <td class="row1" align="center" valign="middle">
+ <img src="#{forums:folderTypeURL(topicrow,moderator.anonymous)}"
+ width="19" height="18"
alt="${resource.Topic_Moved}"
title="${resource.Topic_Moved}"/>
- </td>
- <td class="row1">
+ </td>
+ <td class="row1">
&nbsp;
- <span class="topictitle">${forums:folderType(topicrow)}
- <h:outputLink value="#{forums:outputLink(shared.links['topic'],true)}" styleClass="topictitle">
- <f:param name="t" value="${topicrow.id}"/>
- <h:outputText value="${topicrow.subject}"/>
- </h:outputLink>
+ <span class="topictitle">
+ ${forums:folderType(topicrow)}
+ <h:outputLink value="#{forums:outputLink(shared.links['topic'],true)}"
+ styleClass="topictitle">
+ <f:param name="t" value="${topicrow.id}"/>
+ <h:outputText value="${topicrow.subject}"/>
+ </h:outputLink>
</span>
- </td>
- <td class="row2" align="center" valign="middle"><span
- class="postdetails">${topicrow.replies}</span></td>
- <td class="row1" align="center" valign="middle"><span
- class="postdetails">${topicrow.lastPostDate}</span></td>
- <td class="row2" align="center" valign="middle">
- <h:selectBooleanCheckbox value="#{moderator.checkboxes[topicrow.id]}" />
- </td>
- </tr>
- </c:forEach>
- <tr align="right">
- <td class="catBottom" colspan="5" height="29">
-
- <h:commandButton action="#{moderator.deleteConfirm}" class="liteoption" value="${resource.Delete}">
- <f:param name="f" value="#{forum.forum.id}"/>
- </h:commandButton>
- &nbsp;
- <h:commandButton action="#{moderator.moveConfirm}" class="liteoption" value="${resource.Move}">
+ </td>
+ <td class="row2" align="center" valign="middle">
+ <span class="postdetails">${topicrow.replies}</span>
+ </td>
+ <td class="row1" align="center" valign="middle">
+ <span class="postdetails">${topicrow.lastPostDate}</span>
+ </td>
+ <td class="row2" align="center" valign="middle">
+ <h:selectBooleanCheckbox value="#{moderator.checkboxes[topicrow.id]}"/>
+ </td>
+ </tr>
+ </c:forEach>
+ <tr align="right">
+ <td class="catBottom" colspan="5" height="29">
+ <h:commandButton action="#{moderator.deleteConfirm}"
+ class="liteoption"
+ value="${resource.Delete}">
<f:param name="f" value="#{forum.forum.id}"/>
- </h:commandButton>
- &nbsp;
- <h:commandButton action="#{moderator.lockTopic}" class="liteoption" value="${resource.Lock}">
+ </h:commandButton>
+ &nbsp;
+ <h:commandButton action="#{moderator.moveConfirm}"
+ class="liteoption"
+ value="${resource.Move}">
<f:param name="f" value="#{forum.forum.id}"/>
- </h:commandButton>
- &nbsp;
- <h:commandButton action="#{moderator.unlockTopic}" class="liteoption" value="${resource.Unlock}">
+ </h:commandButton>
+ &nbsp;
+ <h:commandButton action="#{moderator.lockTopic}"
+ class="liteoption"
+ value="${resource.Lock}">
<f:param name="f" value="#{forum.forum.id}"/>
- </h:commandButton>
- </td>
- </tr>
- </table>
- <table width="100%" cellspacing="2" border="0" align="center" cellpadding="2">
- <tr>
- <td align="left" valign="middle">
- <span class="nav">
+ </h:commandButton>
+ &nbsp;
+ <h:commandButton action="#{moderator.unlockTopic}"
+ class="liteoption"
+ value="${resource.Unlock}">
+ <f:param name="f" value="#{forum.forum.id}"/>
+ </h:commandButton>
+ </td>
+ </tr>
+ </table>
+ <table width="100%" cellspacing="2" border="0" align="center"
+ cellpadding="2">
+ <!--<tr>
+ <td align="left" valign="middle">
+ <span class="nav">
<b>#{moderator.pagination}</b>
- </span>
- </td>
- <td align="right" valign="top" nowrap="nowrap">
- <span class="gensmall"></span>
- <br/>
- <span class="nav">#{moderator.pageNumber}</span>
- </td>
- </tr>
-</table>
-</h:form>
-<table width="100%" border="0" cellspacing="0" cellpadding="0">
- <tr>
- <td align="right">
- <ui:include src="/views/jumpbox.xhtml"/>
- </td>
- </tr>
-</table>
+ </span>
+ </td>
+ <td align="right" valign="top" nowrap="nowrap">
+ <br/>
+ <span class="nav">#{moderator.pageNumber}</span>
+ </td>
+ </tr>-->
+ </table>
+ </h:form>
+ <table width="100%" border="0" cellspacing="0" cellpadding="0">
+ <tr>
+ <td align="right">
+ <ui:include src="/views/jumpbox.xhtml"/>
+ </td>
+ </tr>
+ </table>
+ </c:when>
+ <c:otherwise>
+ <table class="forumline" width="100%" cellspacing="1" cellpadding="4" border="0">
+ <tr>
+ <td>
+ <table width="100%" cellspacing="0" cellpadding="1" border="0">
+ <tr>
+ <td>&nbsp;</td>
+ </tr>
+ <tr>
+ <td align="center">
+ <span class="gen">This forum has no posts....</span>
+ </td>
+ </tr>
+ <tr>
+ <td>&nbsp;</td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ </c:otherwise>
+ </c:choose>
</ui:define>
</ui:composition>
-</div>
+</div>
\ No newline at end of file
Modified: labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/moderator/modcp_move.xhtml
===================================================================
--- labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/moderator/modcp_move.xhtml 2006-06-21 22:39:43 UTC (rev 4801)
+++ labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/moderator/modcp_move.xhtml 2006-06-22 01:09:52 UTC (rev 4802)
@@ -31,7 +31,7 @@
xmlns:forums="http://www.jboss.com/products/jbossportal/forums" class="bb">
<ui:composition template="/views/common/common.xhtml">
<ui:define name="mainContent">
- <form>
+ <h:form>
<table width="100%" cellspacing="2" cellpadding="2" border="0"
align="center">
<tr>
@@ -106,7 +106,7 @@
</td>
</tr>
</table>
- </form>
+ </h:form>
<ui:debug key="s" />
</ui:define>
</ui:composition>
|