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

📄 dateselectortag.java

📁 ejb克斯人随风俗
💻 JAVA
字号:
/* Copyright 2004 Sun Microsystems, Inc. All rights reserved.  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:  - Redistributions of source code must retain the above copyright   notice, this list of conditions and the following disclaimer.  - Redistribution in binary form must reproduce the above copyright   notice, this list of conditions and the following disclaimer in   the documentation and/or other materials provided with the   distribution.  Neither the name of Sun Microsystems, Inc. or the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission.  This software is provided "AS IS," without a warranty of any kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.  You acknowledge that Software is not designed, licensed or intended for use in the design, construction, operation or maintenance of any nuclear facility. $Id: DateSelectorTag.java,v 1.1 2004/04/15 03:43:53 yutayoshida Exp $ */package com.sun.j2ee.blueprints.waf.view.taglibs.smart;import javax.servlet.jsp.*;import javax.servlet.jsp.tagext.*;import java.io.*;import java.util.*;/** * HTML 'input' tag. Use with NameTag and ValueTag. */public class DateSelectorTag extends SimpleTagSupport {    private String locale = "en_US";    private String prefix = "date";    private Calendar calendar;        public void setLocale(String locale) {this.locale=locale;}    public void setPrefix(String prefix) {this.prefix=prefix;}         public void setDate(Date d) {        if (locale == null){            calendar = Calendar.getInstance();        } else {            calendar = Calendar.getInstance(new Locale(locale));        }    }        public void setCalendar(Calendar calendar) {        this.calendar = calendar;    }        public void doTag() throws JspTagException, IOException {         JspWriter out = getJspContext().getOut();        // default to current date if not specified        if (calendar == null) {            Date date = new Date();            setDate(date);        }        int day = calendar.get(Calendar.DAY_OF_MONTH) ;        int month = calendar.get(Calendar.MONTH) + 1;        int year = calendar.get(Calendar.YEAR) ;        // create the select tags        if ((locale != null) && locale.toLowerCase().equals("en_us") ||            locale.toLowerCase().equals("en-us")) {            out.print("<label for=\"month_id\">Month:</label>");            createSelect(prefix + "_month", 1 , 12 , month, "month_id", out);            out.print("<label for=\"day_id\">Day:</label>");            createSelect(prefix + "_day", 1, 31, day, "day_id", out);            out.print("<label for=\"year_id\">Year:</label>");            createSelect(prefix + "_year", year, year + 4, year, "year_id", out);        } else if ((locale != null) && locale.toLowerCase().equals("ja_jp") ||            locale.toLowerCase().equals("ja-jp")) {            out.print("<label for=\"year_id\">\u5e74:</label>");            createSelect(prefix + "_year", 2003, 4, year, "year_id", out);            out.print("<label for=\"month_id\">\u6708:</label>");            createSelect(prefix + "_month", 1, 12 , month, "month_id", out);            out.print("<label for=\"day_id\">\u65e5:</label>");            createSelect(prefix + "_day", 1, 31, day, "day_id", out);        }        reset();    }        private void createSelect(String name,                                                      int start,                                                      int count,                                                      int selectedIndex,                                                      String id,                                                     JspWriter out) throws IOException {        out.write("<select name=\"" + name + "\" id=\"" + id + "\">");        for (int loop=start; loop < count +1; loop++) {            if (loop == selectedIndex) {                out.write("<option selected>" + loop + "</option>");            } else {                out.write("<option>" + loop + "</option>");            }        }        out.write("</select>");    }        private void reset() {        locale = "en_US";        prefix = "date";        calendar = null;    }}

⌨️ 快捷键说明

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