重定义wicket分页组件PagingNavigator

1.Navigator.java

package com.logcd.wicket.list;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.navigation.paging.IPageable;
import org.apache.wicket.markup.html.navigation.paging.IPagingLabelProvider;
import org.apache.wicket.markup.html.navigation.paging.PagingNavigation;
import org.apache.wicket.markup.html.navigation.paging.PagingNavigator;
import org.apache.wicket.model.LoadableDetachableModel;

public class Navigator extends PagingNavigator {

private static final long serialVersionUID = 1;

public Navigator(String arg0, final IPageable arg1,final Integer total) {
super(arg0, arg1);
Link totallink = new Link("totallink") {
private static final long serialVersionUID = 1;

@Override
public boolean isEnabled() {
return arg1.getPageCount() - 1 > 0;
}

@Override
public void onClick() {
arg1.setCurrentPage(arg1.getPageCount() - 1);
}
};
totallink.add(new Label("totalcount", new LoadableDetachableModel() {
private static final long serialVersionUID = 1;

@Override
protected Object load() {
return String.valueOf(arg1.getPageCount());
}
}));
this.add(totallink);
this.add(new Label("total",total.toString()));
}

public Navigator(String arg0, final IPageable arg1,
IPagingLabelProvider arg2,final Integer total) {
super(arg0, arg1, arg2);
Link totallink = new Link("totallink") {
private static final long serialVersionUID = 1;

@Override
public boolean isEnabled() {
return arg1.getPageCount() - 1 > 0;
}

@Override
public void onClick() {
arg1.setCurrentPage(arg1.getPageCount() - 1);
}
};
totallink.add(new Label("totalcount", new LoadableDetachableModel() {
private static final long serialVersionUID = 1;

@Override
protected Object load() {
return String.valueOf(arg1.getPageCount());
}
}));
this.add(totallink);
this.add(new Label("total",total.toString()));
}

@Override
protected PagingNavigation newNavigation(IPageable arg0,
IPagingLabelProvider arg1) {
return new PagingSetting("navigation", arg0, arg1, this);
}

}


2.PagingSetting.java:用于,显示控制

package com.logcd.wicket.list;

import org.apache.wicket.markup.html.navigation.paging.IPageable;
import org.apache.wicket.markup.html.navigation.paging.IPagingLabelProvider;
import org.apache.wicket.markup.html.navigation.paging.PagingNavigation;

public class PagingSetting extends PagingNavigation {

private static final long serialVersionUID = 1;

@SuppressWarnings("unused")
private IPageable arg1 = null;

private Navigator style = null;

public PagingSetting(String arg0, IPageable arg1, IPagingLabelProvider arg2,
Navigator style) {
super(arg0, arg1, arg2);
this.arg1 = arg1;
this.style = style;
this.setViewSize(5);
}

@Override
protected void onModelChanged() {
super.onModelChanged();
style.get("first").setVisible(true);
style.get("prev").setVisible(true);
style.get("next").setVisible(true);
style.get("last").setVisible(true);
if (arg1.getCurrentPage() < 2) {
style.get("first").setVisible(false);
}
if (arg1.getCurrentPage() < 1) {
style.get("prev").setVisible(false);
}
if (arg1.getCurrentPage() > arg1.getPageCount() - 2) {
style.get("next").setVisible(false);
}
if (arg1.getCurrentPage() > arg1.getPageCount() - 3) {
style.get("last").setVisible(false);
}
}
}



3.Navigator.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link type="text/css" rel="stylesheet" href="styles/wicket.css"></link>
<link type="text/css" rel="stylesheet" href="styles/office.css"></link>
<meta http-equiv="Content-Type" content="text/html; charset=GBK" />
</head>
<body>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" valign="middle">
<wicket:panel>
<a wicket:id="first" class="text">首页</a>

<a wicket:id="prev" class="text">上一页</a>

<span wicket:id="navigation">  <a wicket:id="pageLink"
href="#"><span wicket:id="pageNumber" class="text">0</span></a> </span>

<a wicket:id="next" class="text">下一页</a>

<a wicket:id="last" class="text">尾页</a>

  总页数:<a wicket:id="totallink" href="#"><span
wicket:id="totalcount">0</span></a> 页  
总记录数:<span wicket:id="total">0</span> 条 
</wicket:panel>
</td>
</tr>
</table>
</body>
</html>


4.应用
(1)java:

form.add(new Navigator("navigator", listView2,listView2.getList().size()));

(2)html:

<style type="text/css">
<!--
i,em{
font-style: normal;
color: #CCCCCC;
}
#datNav{
border:1px solid #8C9EBF;
width:100%;
table-layout:fixed;
line-height: 20px;
background-color:#F4F8FF;
}
-->
</style>

<div class="datNav"><span wicket:id ="navigator">这里显示分页操作</span></div>

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值