Hello. I am trying to do some pagination under Admin Panel for Groups. I made the appropriate changes to the code and i can see the pagination at the end of the page (When admin clicks on groups link under Admin Control Panel). The problem is that the groups page still shows all the groups in one page and shows the pagination at the bottom also which i am sure is not correct because i get a macro exception.
Can someone point me out what am i doing wrong. Thanks.
GroupAction
public void list()
{
System.out.println("Inside list()");
int start = this.preparePagination(DataAccessDriver.getInstance().newGroupDAO().getTotalGroups());
System.out.println("Start is [ " + start + " ] ");
int groupsPerPage = SystemGlobals.getIntValue(ConfigKeys.GROUPS_PER_PAGE);
System.out.println("Groups per page [ " + groupsPerPage + " ] ");
this.context.put("groups", new TreeGroup().getNodes());
this.context.put("grouping", DataAccessDriver.getInstance().newGroupDAO().selectAll(start ,groupsPerPage));
//this.commonData();
this.setTemplateName(TemplateKeys.GROUP_LIST);
}
private int preparePagination(int totalGroups)
{
int start = ViewCommon.getStartPage();
LOG.info("Start is [ " + start + " ]");
int groupsPerPage = SystemGlobals.getIntValue(ConfigKeys.GROUPS_PER_PAGE);
LOG.info("Groups Per Page is [ " + groupsPerPage + " ] ");
ViewCommon.contextToPagination(start, totalGroups, groupsPerPage);
return start;
}
GroupDAO
public int getTotalGroups() ;
public List selectAll(int startFrom, int count) ;
GenericGroupAction
/**
* @see net.jforum.dao.GroupDAO#getTotalGroups()
*/
public int getTotalGroups()
{
PreparedStatement preparedStatement = null;
try {
preparedStatement = JForumExecutionContext.getConnection().prepareStatement(
SystemGlobals.getSql("GroupModel.totalGroups"));
return this.getTotalGroupsCommon(preparedStatement);
}
catch (SQLException e) {
throw new DatabaseException(e);
}
finally {
DbUtils.close(preparedStatement);
}
}
protected int getTotalGroupsCommon(PreparedStatement p) throws SQLException
{
System.out.println("Insid egetTotalGroupsCommon");
ResultSet rs = p.executeQuery();
rs.next();
int total = rs.getInt(1);
rs.close();
p.close();
return total;
}
protected List processSelectAll(ResultSet rs) throws SQLException
{
System.out.println("Inside processSelectAll()");
List list = new ArrayList();
while (rs.next()) {
Group g = new Group();
g.setId(rs.getInt("group_id"));
g.setName(rs.getString("group_name"));
g.setParentId(rs.getInt("parent_id"));
g.setDescription(rs.getString("group_description"));
list.add(g);
}
return list;
}
public List selectAll(int startFrom, int count)
{
System.out.println("Inside selectAll()");
PreparedStatement p = null;
ResultSet rs = null;
try {
if (count > 0) {
p = JForumExecutionContext.getConnection().prepareStatement(
SystemGlobals.getSql("GroupModel.selectAllByLimit"));
p.setInt(1, startFrom);
p.setInt(2, count);
}
else {
p = JForumExecutionContext.getConnection()
.prepareStatement(SystemGlobals.getSql("GroupModel.selectAll"));
}
rs = p.executeQuery();
return this.processSelectAll(rs);
}
catch (SQLException e) {
throw new DatabaseException(e);
}
finally {
DbUtils.close(rs, p);
}
}
SystemGlobals.properties
groupsPerPage = 30
genericqueries.sql
GroupModel.totalGroups = SELECT COUNT(1) as total_groups FROM jforum_groups
GroupModel.selectAllByLimit = SELECT group_id, group_name, parent_id, group_description \
FROM jforum_groups ORDER BY group_name LIMIT ?, ?
group_list.htm
<table width="100%">
<tr>
<td align="right"><#if thisPage?exists><@pagination.doPagination groups/></#if></td>
</tr>
</table>