⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 modelutils.java

📁 分页查询控件 分页查询控件
💻 JAVA
字号:
/* * Copyright 2004 original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *    http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.extremecomponents.base;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import java.util.Set;import javax.servlet.ServletRequest;import org.apache.commons.lang.StringUtils;import org.extremecomponents.table.bean.Table;import org.extremecomponents.table.core.ParameterRegistry;import org.extremecomponents.table.handler.ExportHandler;/** * Helpful utilities for the Table and Tree Model *  * @author Jeff Johnston */public class ModelUtils {    private ModelUtils() {    }    /**     * The page that is going to be displayed.     *      * @param request ServletRequest     * @param collection TableTag collection attribute     * @return     */    public static int getPage(ServletRequest request, String collection) {    	String pagination = request.getParameter(collection + "_" + ParameterRegistry.PAGE);    	int page = 1;        if (!StringUtils.isEmpty(pagination)) {            page = Integer.parseInt(pagination);        }                return page;    }        /**     * The column being sorted, if any.     *      * @param request ServletRequest     * @param collection TableTag collection attribute     * @return     */    public static Map getSort(ServletRequest request, String collection) {    	return getSortedOrFilteredParameters(request, collection, ParameterRegistry.SORT);    }    /**     * The columns being filtered, if any.     *      * @param request ServletRequest     * @param collection TableTag collection attribute     * @return     */    public static Map getFilters(ServletRequest request, String collection) {    	return getSortedOrFilteredParameters(request, collection, ParameterRegistry.FILTER);    }        /**     * Because the rowsDisplayed is a table attribute the only time the value     * is passed is when the rowsDisplayed is changed (usually through Rows Displayed dropdown).     * If the rowsDisplayed is changed then will return what that change is.      * If the value is not changed then will return null. Use the 4 parameter      * getRowsDisplayed() method to abstract out how to find the amount      * of rows that should be displayed.     *      * @param request ServletRequest     * @param collection TableTag collection attribute     * @return     */    private static String getRowsDisplayed(ServletRequest request, String collection)    {        String rowsDisplayed = request.getParameter(collection + "_" + ParameterRegistry.ROWS_DISPLAYED);        if (StringUtils.isNotEmpty(rowsDisplayed)) {            return rowsDisplayed;        }                return null;    }        /**     * Because the rowsDisplayed is a table attribute the only time the value     * is passed is when the rowsDisplayed is changed (usually through Rows Displayed dropdown).     * This is a convience method to abstract out the rules to find out the amount of rows      * that should be displayed.     *      * @param request ServletRequest     * @param collection TableTag collection attribute     * @param defaultRowsDisplayed TableTag rowsDisplayed attribute     * @param totalRows Total possible for result set     * @return     */    public static int getRowsDisplayed(ServletRequest request, String collection, int defaultRowsDisplayed, int totalRows) {        int result = -1;                String rowsDisplayed = getRowsDisplayed(request, collection);        if (StringUtils.isNotBlank(rowsDisplayed)) {            result = Integer.parseInt(rowsDisplayed);        }                if (result == -1) {            result = defaultRowsDisplayed;        }        if (result == 0) {            result = totalRows;        }                return result;    }    /**     * Get the collection of properties and values that was sorted or filtered.     *      * @param parameter Either the ParameterRegistry.FILTER or ParameterRegistry.SORT     * @return Map of property/value pairs     */    private static Map getSortedOrFilteredParameters(ServletRequest request, String collection, String parameter) {        Map subset = null;        Set set = request.getParameterMap().keySet();        for (Iterator iter = set.iterator(); iter.hasNext();) {            if (subset == null) {                subset = new HashMap();            }                        String key = (String) iter.next();            String find =  collection + "_" + parameter;                        if (key.startsWith(find)) {                String value = (String) request.getParameter(key);                if (StringUtils.isNotBlank(value)) {                    subset.put(StringUtils.substringAfter(key, find), value);                }            }        }        return subset;    }        public static boolean isExportMode(ServletRequest request) {        String table = request.getParameter(Table.EXTREME_TABLE);        String exportName = null;        if (StringUtils.isNotBlank(table)) {            exportName = findExportName(request);        }        return StringUtils.isNotBlank(exportName);    }    public static String findInvokeExport(ServletRequest request) {        String table = request.getParameter(Table.EXTREME_TABLE);        if (StringUtils.isNotBlank(table)) {            return request.getParameter(table + ParameterRegistry.EXPORT);        }        return null;    }    public static String findExportName(ServletRequest request) {        String table = request.getParameter(Table.EXTREME_TABLE);        if (StringUtils.isNotBlank(table)) {            return request.getParameter(table + ExportHandler.EXPORT_NAME);        }        return null;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -