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

📄 optionscollectiontag.java

📁 一个实用工具类
💻 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.lang.reflect.InvocationTargetException;import java.util.Iterator;import javax.servlet.jsp.JspException;import org.apache.commons.beanutils.PropertyUtils;import org.apache.struts.util.RequestUtils;import org.apache.struts.util.ResponseUtils;import org.butor.web.action.IButorActionForm;/** * @author nacroaz  * * To change this generated comment edit the template variable "typecomment": * Window>Preferences>Java>Templates. */public class OptionsCollectionTag	extends org.apache.struts.taglib.html.OptionsCollectionTag {    /**     * Process the start of this tag.     *     * @exception JspException if a JSP exception has occurred     */    public int doStartTag() throws JspException {        // Acquire the select tag we are associated with		SelectTag selectTag = (SelectTag)getParent();        if (selectTag == null) {            JspException e = new JspException(                    messages.getMessage("optionsCollectionTag.select"));            RequestUtils.saveException(pageContext, e);            throw e;        }            	// Find and check the form bean    	Object o = RequestUtils.lookup(pageContext, name, null);    	        if (! (o instanceof IButorActionForm)) {			ResponseUtils.write(pageContext, "The form bean must be an instance of ButorActionForm !!!");  			return SKIP_BODY;        }                IButorActionForm form = (IButorActionForm) o;                // If selectTag property is enable, then use super class definition                if ((form.getEnabled(selectTag.getProperty()))) {        	         	return super.doStartTag();        }                // selectTag property is disable        // Acquire the collection containing our options        Object collection = RequestUtils.lookup(pageContext, name, property, null);        if (collection == null) {            JspException e = new JspException(                    messages.getMessage("optionsCollectionTag.collection"));            RequestUtils.saveException(pageContext, e);            throw e;        }        // Acquire an iterator over the options collection        Iterator iter = getIterator(collection);        boolean first = true;        // Render the selected options        while (iter.hasNext()) {            Object bean = iter.next();            Object beanLabel = null;            Object beanValue = null;            // Get the label for this option            try {                beanLabel = PropertyUtils.getProperty(bean, label);                if (beanLabel == null) {                    beanLabel = "";                }            } catch (IllegalAccessException e) {                JspException jspe = new JspException(                        messages.getMessage("getter.access", label, bean));                RequestUtils.saveException(pageContext, jspe);                throw jspe;            } catch (InvocationTargetException e) {                Throwable t = e.getTargetException();                JspException jspe = new JspException(                        messages.getMessage("getter.result", label,                                t.toString()));                RequestUtils.saveException(pageContext, jspe);                throw jspe;            } catch (NoSuchMethodException e) {                JspException jspe = new JspException(                        messages.getMessage("getter.method", label, bean));                RequestUtils.saveException(pageContext, jspe);                throw jspe;            }            // Get the value for this option            try {                beanValue = PropertyUtils.getProperty(bean, value);                if (beanValue == null) {                    beanValue = "";                }            } catch (IllegalAccessException e) {                JspException jspe = new JspException(                        messages.getMessage("getter.access", value, bean));                RequestUtils.saveException(pageContext, jspe);                throw jspe;            } catch (InvocationTargetException e) {                Throwable t = e.getTargetException();                JspException jspe = new JspException(                        messages.getMessage("getter.result", value,                                t.toString()));                RequestUtils.saveException(pageContext, jspe);                throw jspe;            } catch (NoSuchMethodException e) {                JspException jspe = new JspException(                        messages.getMessage("getter.method", value, bean));                RequestUtils.saveException(pageContext, jspe);                throw jspe;            }            String stringLabel = beanLabel.toString();            String stringValue = beanValue.toString();            // Render this option            if (selectTag.isMatched(stringValue)) {            	// Add this option value            	if (first) {            		first = false;	            	} else {            		TagLibHelper.renderText(pageContext, "<BR>", false);            	}                   	TagLibHelper.renderText(pageContext, stringLabel, true);				if (!selectTag.getSaveOnDisable().equals("0")) {            	            	     		       			// Add an hidden field for this property            						TagLibHelper.renderHiddenField(pageContext, selectTag.getProperty(), stringValue);				}            }                    }        return SKIP_BODY;            }}

⌨️ 快捷键说明

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