Clickのカスタムカレンダー
この記事を見てS2Clickのカスタムカレンダー作ってたのを思い出した。
こんな感じのやつ
ソースはこんな感じ
/* * Copyright 2008- kensir0u. * * 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. */ /* * 作成日 :2008/11/12 * パッケージ :org.seasar.s2click.control.sample * ファイル名 :JKLDateField.java */ package org.seasar.s2click.control.sample.control; import java.text.MessageFormat; import javax.servlet.ServletContext; import net.sf.click.extras.control.DateField; import net.sf.click.util.ClickUtils; import net.sf.click.util.HtmlStringBuffer; /** * <i>概要</i>: JKLカレンダークラス * .<p> * JKLカレンダー * * * @author kensir0u * @version 1.0 * @since JDK 5.0 * */ public class JKLDateField extends DateField { /** * <i>概要</i>: シリアルバージョン * .<p> * シリアルバージョンUID * */ private static final long serialVersionUID = 1L; public static final String[] JKLCALENDER_RESOURCES = { "/org/seasar/s2click/control/sample/control/jklcalender/jklcalender.js"}; /** The HTML import statements. */ public static final String HTML_IMPORTS = "<script type=\"text/javascript\" src=\"{0}/click/jklcalender/jklcalender.js\"></script>\n"; /** * 選択可能日(下限) */ private String min_date = null; /** * 選択可能日(上限) */ private String max_date = null; public JKLDateField() { super(); } public JKLDateField(String name, boolean required) { super(name, required); } public JKLDateField(String name, boolean required,String max_date,String min_date) { super(name, required); this.max_date = max_date; this.min_date = min_date; } public JKLDateField(String name, String label, boolean required) { super(name, label, required); } public JKLDateField(String name, String label, boolean required,String max_date,String min_date) { super(name, label, required); this.max_date = max_date; this.min_date = min_date; } public JKLDateField(String name, String label) { super(name, label); } public JKLDateField(String name, String label,String max_date,String min_date) { super(name, label); this.max_date = max_date; this.min_date = min_date; } public JKLDateField(String name) { super(name); } public JKLDateField(String name,String max_date,String min_date) { super(name); this.max_date = max_date; this.min_date = min_date; } /* * (non-Javadoc) * @see net.sf.click.Control#onDeploy(javax.servlet.ServletContext) */ public void onDeploy(ServletContext servletContext) { ClickUtils.deployFiles(servletContext, JKLCALENDER_RESOURCES, "click/jklcalender"); } /** * Return the JKLDateField <tt>JKLCalendar.js</tt> includes. * * @return the HTML head import statements for the control JavaScript file */ public String getHtmlImports() { if (isDisabled()) { return null; } Object args[] = { getContext().getRequest().getContextPath() }; return MessageFormat.format(HTML_IMPORTS, args); } /** * Return the HTML rendered Date Field string. * * @return the HTML rendered Date Field string */ public String toString() { HtmlStringBuffer buffer = new HtmlStringBuffer(); String textField = super.toString(); buffer.append(textField); if (!isDisabled()) { buffer.append("<img align=\"top\" "); buffer.append(" src=\""); buffer.append(getContext().getRequest().getContextPath()); buffer.append("/click/calendar/calendar.gif\" id=\""); buffer.append(getId()); buffer.append("-button\" "); String calendarTitle = getMessage("calendar-image-title"); buffer.appendAttribute("alt", calendarTitle); buffer.appendAttribute("title", calendarTitle); String objName = "cal_" + getName(); buffer.appendAttribute("onclick", objName + ".write();"); buffer.appendAttribute("onChange", objName + ".getFormValue(); " + objName + ".hide();"); buffer.elementEnd(); buffer.append("<script type=\"text/javascript\">\n"); buffer.append("var " + objName + " = new JKL.Calendar(\"" + objName + "\",\"" + form.getId() + "\",\""+ getName() + "\");"); buffer.append(""); if (getMin_date() != null) { buffer.append(objName + ".min_date = new Date(\"" + getMin_date() + "\");"); } if (getMax_date() != null) { buffer.append(objName + ".max_date = new Date(\"" + getMax_date() + "\");"); } buffer.append("</script> \n"); buffer.append("<div id=\"" + objName + "\"></div>"); } return buffer.toString(); } /** * <i>概要(abstract)</i>: Return the {@link org.seasar.s2click.control.sample.control.JKLDateField#min_date} * .<p> * Return the {@link org.seasar.s2click.control.sample.control.JKLDateField#min_date}. * * @return the min_date */ public String getMin_date() { return min_date; } /** * <i>概要(abstract)</i>:Set the {@link org.seasar.s2click.control.sample.control.JKLDateField#min_date} * .<p> * Set the {@link org.seasar.s2click.control.sample.control.JKLDateField#min_date}. * * @param min_date the min_date to set */ public void setMin_date(String min_date) { this.min_date = min_date; } /** * <i>概要(abstract)</i>: Return the {@link org.seasar.s2click.control.sample.control.JKLDateField#max_date} * .<p> * Return the {@link org.seasar.s2click.control.sample.control.JKLDateField#max_date}. * * @return the max_date */ public String getMax_date() { return max_date; } /** * <i>概要(abstract)</i>:Set the {@link org.seasar.s2click.control.sample.control.JKLDateField#max_date} * .<p> * Set the {@link org.seasar.s2click.control.sample.control.JKLDateField#max_date}. * * @param max_date the max_date to set */ public void setMax_date(String max_date) { this.max_date = max_date; } }