01: /*
02: * (C) Copyright 2004 Nabh Information Systems, Inc.
03: *
04: * All copyright notices regarding Nabh's products MUST remain
05: * intact in the scripts and in the outputted HTML.
06: * This program is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public License
08: * as published by the Free Software Foundation; either version 2.1
09: * of the License, or (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public License
17: * along with this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19: *
20: */
21: package com.nabhinc.portlet.mvcportlet.taglib;
22:
23: import java.io.IOException;
24:
25: import javax.portlet.RenderRequest;
26: import javax.servlet.jsp.JspException;
27: import javax.servlet.jsp.JspWriter;
28:
29: import com.nabhinc.util.i18n.DateTimeFormatUtil;
30:
31: /**
32: * Submit button element tag.
33: *
34: * @author Padmanabh Dabke
35: * (c) 2004 Nabh Information Systems, Inc. All Rights Reserved.
36: */
37: public class SelectTimestampTag extends InputTag {
38: /**
39: *
40: */
41: private static final long serialVersionUID = 2748845548658539445L;
42:
43: public SelectTimestampTag() {
44: super ();
45: setType("text");
46: setSize(10);
47:
48: }
49:
50: public int doStartTag() throws JspException {
51: super .doStartTag();
52: RenderRequest request = (RenderRequest) pageContext
53: .getRequest().getAttribute("javax.portlet.request");
54: JspWriter out = pageContext.getOut();
55: String datePattern = getDateFormatPattern(request);
56: try {
57: out
58: .print("<input type=\"reset\" value=\" ... \" onclick=\"return showCalendar('"
59: + getId()
60: + "', '"
61: + datePattern
62: + "', '24', true);\" />");
63: } catch (IOException e) {
64: throw new JspException(e);
65: }
66: return SKIP_BODY;
67: }
68:
69: private String getDateFormatPattern(RenderRequest req) {
70: String format = com.nabhinc.util.i18n.DateTimeFormatUtil
71: .getDateTimeFormatPattern(req.getLocale());
72: format = format.replaceFirst("yyyy", "%Y");
73: format = format.replaceFirst("yy", "%y");
74: format = format.replaceFirst("MM", "%m");
75: format = format.replaceFirst("dd", "%d");
76: format = format.replaceFirst("hh", "%I");
77: format = format.replaceFirst("kk", "%H");
78: format = format.replaceFirst("HH", "%H"); // HH (0 - 23); H (1 - 24)
79: format = format.replaceFirst("h", "%l"); // hour without padding 0
80: format = format.replaceFirst("mm", "%M");
81: format = format.replaceFirst("a", "%p"); // upper case: AM/PM
82: // format = format.replaceFirst("a", "%P"); // lower case: am/pm
83:
84: return format;
85: }
86:
87: }
|