大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺
安装要求
1、Servlet 2.3 或更高
2、 JDK 1.3.1 或更高
最小的Jars需求
1、commons-beanutils 1.6
2、commons-collections 3.0
3、 commons-lang 2.0
4、 commons-logging 1.0.4
5、 standard 1.0.2
PDF 导出要用到的包:
1、 avalon-framework 4.0
2、batik 1.5-fop-0.20-5
3、 fop 0.20.5
4、 xalan 2.5.1
5、 xercesImpl 2.6.1
6、 xml-apis 2.0.2
XLS 导出要用到的包:
1、 poi-2.5.1.jar
格式化输出表单中的数据
Q:怎么样格式化输出表单中的数据
A: 你可以设置列的cell:
- 日期格式化: cell = ” date ” format = ” yyyy-MM-dd ”
- 数字格式化: cell=”currency” format=”###,###,##0.00″
在web.xml中添加编码过滤器配置:
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>gb2312</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!–配置导出功能的过滤器–>
<filter>
<filter-name>eXtremeExport</filter-name>
<filter-class>org.extremecomponents.table.filter.ExportFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>eXtremeExport</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
在extComments中加入链接
Q:怎么样加入链接
A: 你可以参考下例:
<ec:table
var="pres"
items="presidents"
action="${pageContext.request.contextPath}/compact.run"
imagePath="${pageContext.request.contextPath}/images/table/compact/*.gif"
view="compact"
title="Compact Toolbar View"
showTooltips="false"
>
<ec:exportPdf
fileName="output.pdf"
tooltip="Export PDF"
headerColor="black"
headerBackgroundColor="#b6c2da"
headerTitle="Presidents"
text="PDF"
/>
<ec:exportXls
fileName="output.xls"
tooltip="Export Excel"
text="XLS"
/>
<ec:row>
<ec:column property="fullName" title="Name">
<a href="http://www.whitehouse.gov/history/presidents/">${pres.fullName}</a>
</ec:column>
<ec:column property="nickName"/>
<ec:column property="term"/>
<ec:column property="born" cell="date"/>
<ec:column property="died" cell="date"/>
<ec:column property="career"/>
</ec:row>
</ec:table>
Limit数据端分页
package com.sinovs.saler.webapp.action;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.DispatchAction;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.extremecomponents.table.context.Context;
import org.extremecomponents.table.context.HttpServletRequestContext;
import org.extremecomponents.table.core.Preferences;
import org.extremecomponents.table.core.PreferencesConstants;
import org.extremecomponents.table.core.TableConstants;
import org.extremecomponents.table.core.TableModelUtils;
import org.extremecomponents.table.core.TableProperties;
import org.extremecomponents.table.limit.Limit;
import org.extremecomponents.table.limit.LimitFactory;
import org.extremecomponents.table.limit.TableLimit;
import org.extremecomponents.table.limit.TableLimitFactory;
import com.sinovs.saler.model.Saler;
import com.sinovs.saler.service.SalerManager;
public final class SalerAction extends DispatchAction {
public ActionForward search(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
//从spring中得到的bean
SalerManager mgr = (SalerManager) getBean("salerManager");
/**
* controller首先需要创建一个Limit
*/
String tableId = "ec";
Context context = new HttpServletRequestContext(request);
LimitFactory limitFactory = new TableLimitFactory(context, tableId);
Limit limit = new TableLimit(limitFactory);
/**
* 得到系统默认的页面显示大小
*/
Preferences preferences = new TableProperties();
preferences.init(null, TableModelUtils.getPreferencesLocation(context));
String crdStr = tableId + "_" + TableConstants.CURRENT_ROWS_DISPLAYED;
/**
* 注意:此处取值时,如果后台配置文件里有配置,就从里面取,反之取15
*/
int defaultRowsDisplayed = Integer.parseInt(preferences
.getPreference(PreferencesConstants.TABLE_ROWS_DISPLAYED));
if (request.getParameter(crdStr) != null) {
defaultRowsDisplayed = Integer.parseInt(request
.getParameter(crdStr));
}
/**
* limit需要得到所有的行来得到行的信息
*/
int totalRows = mgr.getTotalSalers(limit);
limit.setRowAttributes(totalRows, defaultRowsDisplayed);
/**
* 需要从services得到Collection数据
*/
List list = mgr.getSalers(limit);
/**
* 将Collections和totalRow这些信息传送回JSP以便eXtremeTable知道如何显示这些信息
*/
request.setAttribute("list", list);
request.setAttribute("totalRows", new Integer(totalRows));
return mapping.findForward("list");
}
}
SalerManagerImpl
/**
* controller需要到第一条信息就是总行数。
*/
private final static String salersQuery = "FROM Saler ";
private final static String totalSalersQuery = "SELECT count(*) FROM Saler ";
public int getTotalSalers(Limit limit) {
String totalQuery = totalSalersQuery;
String modTotalQuery = filterQuery(limit.getFilterSet(), totalQuery);
int totalRows = dao.getTotalSalers(modTotalQuery);
return totalRows;
}
public List getSalers(Limit limit) {
String query = salersQuery;
String modSalersQuery = filterQuery(limit.getFilterSet(), query);
modSalersQuery = sortQuery(limit.getSort(), modSalersQuery);
return dao.getSalers(modSalersQuery, limit);
}
private String filterQuery(FilterSet filterSet, String query) {
if (!filterSet.isFiltered() || filterSet.isCleared()) {
return query;
}
Filter filters[] = filterSet.getFilters();
for (int i = 0; i < filters.length; i++) {
Filter filter = filters[i];
String property = filter.getProperty();
String value = filter.getValue();
query = filterQuery(query, property, value);
}
return query;
}
public String filterQuery(String query, String property, String value) {
StringBuffer result = new StringBuffer(query);
if (query.indexOf("WHERE") == -1) {
result.append(" WHERE 1 = 1 "); // stub WHERE clause so can just
// append AND clause
}
result.append(" AND " + property + " like '%" + value + "%'");
return result.toString();
}
private String sortQuery(Sort sort, String query) {
if (!sort.isSorted()) {
return query;
}
String property = sort.getProperty();
String sortOrder = sort.getSortOrder();
return sortQuery(query, property, sortOrder);
}
public String sortQuery(String query, String property, String sortOrder) {
StringBuffer result = new StringBuffer(query + " ORDER BY ");
result.append(property + " " + sortOrder);
return result.toString();
}
SalerDaoHibernate
/**
* 得到数据总行数
*/
public int getTotalSalers(String query) {
int totalRows = 0;
List list = getHibernateTemplate().find(query);
if (list.size() > 0) {
totalRows = ((Integer) list.get(0)).intValue();
}
return totalRows;
}
/**
* 根据HQL语句的到纪录列表
*/
public List getSalers(String query, Limit limit) {
Session session = this.getSession();
Query q = session.createQuery(query);
q.setFirstResult((limit.getPage() - 1)
* limit.getCurrentRowsDisplayed());
q.setMaxResults(limit.getCurrentRowsDisplayed());
return q.list();
}
页面
<ec:table
items="salerList"
var="saler"
action="${pageContext.request.contextPath}/saler.do?method=search"
imagePath="${pageContext.request.contextPath}/images/table/*.gif"
title="saler.list.title"
width="80%"
retrieveRowsCallback="org.extremecomponents.table.callback.LimitCallback" filterRowsCallback="org.extremecomponents.table.callback.LimitCallback" sortRowsCallback="org.extremecomponents.table.callback.LimitCallback"
rowsDisplayed="16"
>
<ec:exportXls fileName="presidents.xls" tooltip="Export Excel"/>
<ec:row highlightRow="true">
<ec:column property="rowcount" cell="rowCount" sortable="false" filterable="false" title="ID" width="60"/>
<ec:column property="salerName" title="saler.salername"/>
<ec:column property="salerPhone" title="saler.salerphone"/>
<ec:column property="id" title="saler.button.mod" filterable="false" viewsAllowed="html" sortable="false">
<a href="${pageContext.request.contextPath}/saler.do?method=edit&id=${saler.id}"><bean:message key="saler.button.mod"/></a>
</ec:column>
<ec:column property="id" title="saler.button.delete" filterable="false" sortable="false" viewsAllowed="html">
<a href="${pageContext.request.contextPath}/saler.do?method=delete&id=${saler.id}"><bean:message key="saler.button.delete"/></a>
</ec:column>
</ec:row>
</ec:table>
创建Limit
首先你需要通过LimitFactory得到一个Limit实例:
Context context = new HttpServletRequestContext(request);
LimitFactory limitFactory = new TableLimitFactory(context, tableId);
Limit limit = new TableLimit(limitFactory);
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/171318.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...