package com.exam.taglib.table;
import org.apache.struts2.components.UIBean;
import org.apache.struts2.views.annotations.StrutsTag;
import org.apache.struts2.views.annotations.StrutsTagAttribute;
import com.opensymphony.xwork2.util.ValueStack;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* struts2版的分页标签
*
*/
@StrutsTag(name = "pager", tldTagClass = "org.icim.pager.struts2.PagerTag", description = "struts2 pager by ithink")
public class Pager extends UIBean {
final public static String TEMPLATE = "pager";
protected String totalRecord;
protected String totalPage;
protected String curPage;
protected String pageLimit;
protected String url;
protected String curCssClass;
protected String showTotalPage;
protected String showTotalRecord;
protected String directJumpType;
public Pager(ValueStack stack, HttpServletRequest request,
HttpServletResponse response) {
super(stack, request, response);
}
/**
* 用于返回模板的名字,Struts2会自动在后面加入.ftl扩展名以找到特定的模板文件。
*/
@Override
protected String getDefaultTemplate() {
return TEMPLATE;
}
/**
* 设置UIBean的属性,一般Tag中有几个这样的属性,这里就有几个 StrutsTagAttribute注解,说明该属性是int类型,这一步很重要
*
* @param totalPage
*/
@StrutsTagAttribute(description = "total records", type = "Long")
public void setTotalRecord(String totalRecord) {
this.totalRecord = totalRecord;
}
@StrutsTagAttribute(description = "total pages", type = "Integer")
public void setTotalPage(String totalPage) {
this.totalPage = totalPage;
}
@StrutsTagAttribute(description = "current page", type = "Integer")
public void setCurPage(String curPage) {
this.curPage = curPage;
}
@StrutsTagAttribute(description = "how many pages in a panel once", type = "Integer")
public void setPageLimit(String pageLimit) {
this.pageLimit = pageLimit;
}
@StrutsTagAttribute(description = "url to be linked", type = "String")
public void setUrl(String url) {
this.url = url;
}
@StrutsTagAttribute(description = "css style of current page", type = "String")
public void setCurCssClass(String curCssClass) {
this.curCssClass = curCssClass;
}
@StrutsTagAttribute(description = "whether to show totalPage", type = "Boolean", defaultValue = "true")
public void setShowTotalPage(String showTotalPage) {
this.showTotalPage = showTotalPage;
}
@StrutsTagAttribute(description = "whether to show currentPage", type = "Boolean", defaultValue = "false")
public void setShowTotalRecord(String showTotalRecord) {
this.showTotalRecord = showTotalRecord;
}
// TODO 直接页面跳转
// 这里的directJumpType默认值为none, 可选值为 'select', 'goto'
@StrutsTagAttribute(description = "show type of direct jump type. such as select,textbox which can lead going to a page directly", type = "String", defaultValue = "none")
public void setDirectJumpType(String directJumpType) {
this.directJumpType = directJumpType;
}
/**
* 重写evaluateExtraParams()方法,在UIBean初始化后会调用这个方法来初始化设定参数,如addParameter方法,会在freemarker里的parameters里加入一个key
* value。这里要注意findString,还有相关的findxxxx方法,它们是已经封装好了的解释ognl语法的工具,具体是怎么样的,大家可以查看一下UIBean的api
* doc
*/
@Override
protected void evaluateExtraParams() {
super.evaluateExtraParams();
// findValue()方法本身已对OGNL进行了处理
if (totalRecord != null) {
addParameter("totalRecord", findValue(totalRecord));
}
if (totalPage != null) {
addParameter("totalPage", findValue(totalPage));
}
if (curPage != null) {
addParameter("curPage", findValue(curPage));
}
if (pageLimit != null) {
addParameter("pageLimit", findValue(pageLimit));
}
if (url != null) {
addParameter("url", findValue(url, String.class));
}
if (curCssClass != null) {
addParameter("curCssClass", findValue(curCssClass,String.class));
}
if (showTotalPage != null) {
addParameter("showTotalPage", findValue(showTotalPage,
Boolean.class));
}
if (showTotalRecord != null) {
addParameter("showTotalRecord", findValue(showTotalRecord,Boolean.class));
}
if (directJumpType != null) {
addParameter("directJumpType", findValue(directJumpType));
}
}
}
载自http://code.google.com/p/chinese-exam/source/browse/trunk/exam/src/com/exam/taglib/table/Pager.java?r=2
分享到:
相关推荐
tag struts2 自定义标签 实例 tag struts2的自定义标签实例
自定义标签主要包括三个步骤: 1、编写java类,继承TagSupport类; 2、创建tld文件,影射标签名和标签的java类; 3、jsp页面引入tld。 博文地址:http://blog.csdn.net/itmyhome1990/article/details/50718282
自定义标签,直接代码,直接模仿开发即可 public class ButtonTag extends AttributeTag { //tld中定义的属性 public String label; public String url; public String click; public String confirm; public ...
HttpSession session = this.pageContext.getSession(); 资源的方法同上。故不用下载资源。
主要介绍了Struts2 自定义下拉框Tag标签的相关资料,需要的朋友可以参考下
struts2的自定义标签写法,并且有一个例子代码。
NULL 博文链接:https://mr-cheney.iteye.com/blog/1057176
该属性指定Struts 2应用加载用户自定义的属性文件,该自定义属性文件指定的属性不会覆盖struts.properties文件中指定的属性.如果需要加载多个自定义属性文件,多个自定义属性文件的文件名以英文逗号(,)隔开. struts....
2.自定义拦截器 28 方式一,实现Interceptor接口。 28 方式二、继承AbstractInterceptor抽象类 29 方式三、继承MethodFilterInteceptor类 30 3.使用来MethodFilterInterceptor灵活拦截 32 4.使用默认的execAndWait...
Struts 2 标签库(文档手册) Tags-API-CLSW-JSP <%@ taglib prefix="s" uri="/struts-tags" %> 就能使用struts2.0的标签库 下面就介绍每个标签的具体应用实例说明:按字母排列 A: 1. 2. <s:a href=""></s:a>-...
jsp自定义标签,比如说if,foreach,out,format
掌握自定义jsp标签 <br> JSP中有一块重要的技术:自定义标签(Custom Tag),最近这几天在学习Struts的时候发现Struts中使用了很多自定义标签,如html、bean等。所以我就做了个简单的试验,学习一下这种技术。...
自定义tag 4.show.jsp列表的empID字段的sort 5.struts的validate 6.ajax实现的分页 7.ajax实现了省市下拉列表的联动 8.ajax的文件上传 9.批量删除 10.token控制刷新提交 11.简单的excl报表 12.简单的...
哦 忘记介绍了, 当中还有本人写的几个自定义标签:com.light.framework.tag 自定义标签的帮助类:com.light.framework.tagAssistant 还有登录拦截器:com.light.framework.interceptor 字符集过滤器:...
受dynamic attribute影响的struts tag,使用了列表之外的属性,即自定义属性,即可视为存在S2-061,在知道参数的情况下,可以执行OGNL 表达式 filter by python default struts tag list, these dynamic-attribute ...
更新内容: 在原来的版本中, 如果一个路径没有在struts-config.xml文件中配置, 返回的是一个404错误页面, 现在, 如果一个请求路径没有在标签中配置, 我们可以自定义返回的错误页面. 使用示例: 如果你想要使用这个...
为在页面中表现自定义对象的一组自定义tag 包含JSP页面的JSF应用程序也使用由为了表现UI组件和在页面上的其他对象的JSF技术而定义的标准的tag库。 Java Server Faces技术的重要开发框架 sun-ri、myfaces、...
15.4. Struts 15.4.1. ContextLoaderPlugin 15.4.2. ActionSupport 类 15.5. Tapestry 15.5.1. 注入 Spring 托管的 beans 15.6. WebWork 15.7. 更多资源 16. Portlet MVC框架 16.1. 介绍 16.1.1. 控制器 - ...
15.4. Struts 15.4.1. ContextLoaderPlugin 15.4.2. ActionSupport Classes 15.5. Tapestry 15.5.1. 注入 Spring 托管的 beans 15.6. WebWork 15.7. 更多资源 16. Portlet MVC框架 16.1. 介绍 16.1.1. 控制...