會員註冊 / 登入  |  電腦版  |  Jump to bottom of page

JForum中文社群 JForum Chinese Users Community » Pagination issue

發表人: acer123, 九級學員
2009-10-16 12:03:45
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>

發表人: acer123, 九級學員
2009-10-16 12:09:42
And i created a variable in ConfigKeys.java also for GROUPS_PER_PAGE

發表人: acer123, 九級學員
2009-10-16 13:23:00
Ah appologies for the double post. Actually i was trying to edit and instead i later on realized that i quoted :--(. I was able to make it work. What i did is made some changes in group_list.htm file in admin. I can see the pagination and the first page displays 30 records. But when i click on second page i get a nasty exception.



<#list grouping as group>

<tr>
<td class="row1"><span class="gen">${group.name}</span></td>
<td class="row1" align="center"><span class="gen"><a href="${contextPath}/${moduleName}/edit/${group.id}${extension}">${I18n.getMessage("Groups.List.Edit")}</a></span></td>
<td class="row1" align="center"><input type="checkbox" name="group_id" value="${group.id}" /></td>
<td class="row1" align="center"><span class="gen"><a href="${contextPath}/${moduleName}/permissions/${group.id}${extension}">${I18n.getMessage("Permissions")}</a></span></td>
</tr>

</#list>
.
.
.

<table width="100%">
<tr>
<td align="right"><#if thisPage?exists><@pagination.doPagination grouping/></#if></td>
</tr>
</table>



When i click on the second page this is what i get :-

<a id="myprofile" class="mainmenu" href=" Expression session is undefined on line 67, column 162 in default/header.htm. The problematic instruction: ---------- ==> ${session.userId} [on line 67, column 160 in default/header.htm] in include "header.htm" [on line 1, column 1 in default/message.htm] in include "${templateName}/message.htm" [on line 7, column 9 in exception.html] ---------- Java backtrace for programmers: ---------- freemarker.core.InvalidReferenceException: Expression session is undefined on line 67, column 162 in default/header.htm. at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:124) at freemarker.core.TemplateObject.invalidTypeException(TemplateObject.java:134) at freemarker.core.Dot._getAsTemplateModel(Dot.java:78) at freemarker.core.Expression.getAsTemplateModel(Expression.java:89) at freemarker.core.Expression.getStringValue(Expression.java:93) at freemarker.core.DollarVariable.accept(DollarVariable.java:76) at freemarker.core.Environment.visit(Environment.java:196) at freemarker.core.MixedContent.accept(MixedContent.java:92) at freemarker.core.Environment.visit(Environment.java:196) at freemarker.core.Environment.renderElementToString(Environment.java:1461) at freemarker.core.StringLiteral.getStringValue(StringLiteral.java:95) at freemarker.core.StringLiteral._getAsTemplateModel(StringLiteral.java:80) at freemarker.core.Expression.getAsTemplateModel(Expression.java:89) at freemarker.core.ListLiteral.getModelList(ListLiteral.java:119) at freemarker.core.MethodCall._getAsTemplateModel(MethodCall.java:89) at freemarker.core.Expression.getAsTemplateModel(Expression.java:89) at freemarker.core.Expression.getStringValue(Expression.java:93) at freemarker.core.DollarVariable.accept(DollarVariable.java:76) at freemarker.core.Environment.visit(Environment.java:196) at freemarker.core.MixedContent.accept(MixedContent.java:92) at freemarker.core.Environment.visit(Environment.java:196) at freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:79) at freemarker.core.Environment.visit(Environment.java:196) at freemarker.core.MixedContent.accept(MixedContent.java:92) at freemarker.core.Environment.visit(Environment.java:196) at freemarker.core.Environment.include(Environment.java:1375) at freemarker.core.Include.accept(Include.java:155) at freemarker.core.Environment.visit(Environment.java:196) at freemarker.core.MixedContent.accept(MixedContent.java:92) at freemarker.core.Environment.visit(Environment.java:196) at freemarker.core.Environment.include(Environment.java:1375) at freemarker.core.Include.accept(Include.java:155) at freemarker.core.Environment.visit(Environment.java:196) at freemarker.core.IfBlock.accept(IfBlock.java:82) at freemarker.core.Environment.visit(Environment.java:196) at freemarker.core.MixedContent.accept(MixedContent.java:92) at freemarker.core.Environment.visit(Environment.java:196) at freemarker.core.Environment.process(Environment.java:176) at freemarker.template.Template.process(Template.java:232) at net.jforum.exceptions.ExceptionWriter.handleExceptionData(ExceptionWriter.java:115) at net.jforum.JForum.handleException(JForum.java:285) at net.jforum.JForum.service(JForum.java:205) at javax.servlet.http.HttpServlet.service(HttpServlet.java:803) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188) at net.jforum.util.legacy.clickstream.ClickstreamFilter.doFilter(ClickstreamFilter.java:59) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874) at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665) at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528) at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689) at java.lang.Thread.run(Thread.java:595)

發表人: andowson, 七段學員
2009-10-16 16:02:33
There is an exception occurred when you clicked on the second page. You need to find out the URL of the second page. Check if the URL is correct.

發表人: acer123, 九級學員
2009-10-16 21:28:52
Hi adwoson. Thanks for your reply. I output the URL and it states :-

http://localhost:8080/jforum/adminGroups/list-30?null

The parameter i get for the second page is null hence the exception. I tried several senarious but just could not find a way to fix it. Any hints.

發表人: acer123, 九級學員
2009-10-16 21:33:08
And in the group-list.htm where it uses the group-macros.ftl i replaced the looping with th <#list>. I am sure that should not be an issue

發表人: acer123, 九級學員
2009-10-19 05:41:36
Ok i was able to fix the issue by adding :-

adminGroups.list.0 =

It worked perfectly. Hopefully people who are trying to do pagination can find this post helpful.

發表人: sudiliuxin, 十級學員
2009-10-22 16:57:04
acer123:
我抄了你的代码到我的系统上,出现这样的错误
URL is: /jforum/adminGroups/list.page?null
The problematic instruction:
----------
==> user-directive pagination.doPagination [on line 61, column 40 in community/admin/group_list.htm]
----------

Java backtrace for programmers:
----------
freemarker.core.InvalidReferenceException: Expression pagination is undefined on line 61, column 42 in community/admin/group_list.htm.
at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:124)
at freemarker.core.TemplateObject.invalidTypeException(TemplateObject.java:134)
at freemarker.core.Dot._getAsTemplateModel(Dot.java:7smilie
另外说明的事情是:
1.在group_list.htm页面我是直接把下面的代码加在页的最后面
<table class="forumline" cellspacing="1" cellpadding="3" width="100%" border="0">
<#list grouping as group>
<tr>
<td class="row1"><span class="gen">${group.name}</span></td>
<td class="row1" align="center"><span class="gen"><a href="${contextPath}/${moduleName}/edit/${group.id}${extension}">${I18n.getMessage("Groups.List.Edit")}</a></span></td>
<td class="row1" align="center"><input type="checkbox" name="group_id" value="${group.id}" /></td>
<td class="row1" align="center"><span class="gen"><a href="${contextPath}/${moduleName}/permissions/${group.id}${extension}">${I18n.getMessage("Permissions")}</a></span></td>
</tr>
</#list>
</table>
<table width="100%">
<tr>
<td align="right"><#if thisPage?exists><@pagination.doPagination grouping/></#if></td>
</tr>
</table>
2.你说Ok i was able to fix the issue by adding :-
adminGroups.list.0 =
而urlPattern.properties 早久有这样的定义了
请问要怎么修改才能够实现分组呢?特别是group_list.htm需要怎么改写
请求你的帮助,我的EMAIL:liuxinsudi@163.com

發表人: acer123, 九級學員
2009-10-28 10:16:13
Could you please show me the code for the one which you are having issues with pagination ?. All you need to do is in xyzAction.java add :-

this.context.put("action",action);

and in the JSP page at the bottom where they have the pagination you need to put action in there thats all




會員註冊 / 登入  |  電腦版  |  Jump to top of page