📄 resultcounttag.java
字号:
/* * Copyright (C) butor.com. All rights reserved. * * This software is published under the terms of the GNU Library General * Public License (GNU LGPL), a copy of which has been included with this * distribution in the LICENSE.txt file. */package org.butor.web.taglib.html;import java.io.IOException;import java.util.Collection;import java.util.Locale;import javax.servlet.jsp.JspException;import javax.servlet.jsp.JspWriter;import javax.servlet.jsp.tagext.TagSupport;import org.apache.struts.taglib.html.Constants;import org.apache.struts.util.RequestUtils;import org.butor.log.Log;import org.butor.messageResources.MessageResourcesService;import org.butor.web.context.IWebContext;import org.butor.web.context.WebContextService;/** * Show the count of a search result. * * @author Aiman SAWAN */public class ResultCountTag extends TagSupport { protected Integer f_size = null; protected String f_size_property = null; protected String f_collection_property = null; protected int f_tableWidth = 100; protected String f_prefix_key = null; protected String f_suffix_key = null; protected String f_view_mode = null; /** * The name of the bean containing our underlying property. */ protected String f_name = Constants.BEAN_KEY; /** * @see Tag#doStartTag() */ public int doStartTag() throws JspException { IWebContext context = WebContextService.getContext(); if (context == null) { Log.logStr(this, Log.LOG_TYPE_ERROR, "doStartTag()", "Got null context!"); return EVAL_PAGE; } Locale locale = context.getLocale(); if (f_size == null && f_name != null) { Collection collection = null; // is the bean specified by size_property is a collection? if (f_size_property != null) { f_size = (Integer) RequestUtils.lookup(pageContext, f_name, f_size_property, null); } if (f_size == null) { // is the bean specified by collection_property is a collection? if (f_collection_property != null) { collection = (Collection) RequestUtils.lookup(pageContext, f_name, f_collection_property, null); } // is the bean specified by name is a collection? if (collection == null) { collection = (Collection) RequestUtils.lookup(pageContext, f_name, null); } if (collection == null) { Log.logStr(this, Log.LOG_TYPE_ERROR, "doStartTag()", "nor name and collection_property objects are instance of Collection!"); f_size = new Integer(0); } else { f_size = new Integer(collection.size()); } } } if (f_view_mode == null) { f_view_mode = "1"; // Generate table } try { JspWriter writer = pageContext.getOut(); if (f_view_mode.equals("1")) { writer.print("<table width=\""); writer.print(f_tableWidth); writer.print("%\" class=\"stat\">"); writer.print("<tr><th class=\"stat\">"); } else { writer.print("<span>"); } if (f_prefix_key != null) { writer.print(MessageResourcesService.getMessage(locale, f_prefix_key)); writer.print(" - "); } writer.print(f_size); writer.print(" "); writer.print(MessageResourcesService.getMessage(locale, "label.count")); if (f_suffix_key != null) { writer.print(" - "); writer.print(MessageResourcesService.getMessage(locale, f_suffix_key)); } if (f_view_mode.equals("1")) { writer.println("</th></tr></table>"); } else { writer.print("</span>"); } } catch (IOException e) { throw new JspException(e); } return EVAL_PAGE; } public void setTableWidth(int value) { f_tableWidth = value; } public int getTableWidth() { return f_tableWidth; } /** * bean name */ public void setName(String name) { f_name = name; } public void setSize(Integer value) { f_size = value; } public Integer getSize() { return f_size; } public void setSize_property(String value) { f_size_property = value; } public String getSize_property() { return f_size_property; } public void setCollection_property(String value) { f_collection_property = value; } public String getCollection_property() { return f_collection_property; } public void setPrefix_key(String key) { f_prefix_key = key; } public void setSuffix_key(String key) { f_prefix_key = key; } public String getPrefix_key() { return f_prefix_key; } public String getSuffix_key() { return f_suffix_key; } public String getView_mode() { return f_view_mode; } public void setView_mode(String mode) { f_view_mode = mode; } /** * Release any acquired resources. */ public void release() { super.release(); f_size = null; f_collection_property = null; f_name = null; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -