1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.sys.document.web.renderers;
17
18 import java.io.IOException;
19
20 import javax.servlet.jsp.JspException;
21 import javax.servlet.jsp.JspWriter;
22 import javax.servlet.jsp.PageContext;
23 import javax.servlet.jsp.tagext.Tag;
24
25 import org.kuali.ole.sys.context.SpringContext;
26 import org.kuali.rice.core.api.config.property.ConfigurationService;
27
28
29
30
31 public class DateRenderer extends TextRenderer {
32
33
34
35
36
37 @Override
38 public void clear() {
39 super.clear();
40 }
41
42
43
44
45
46 @Override
47 public void render(PageContext pageContext, Tag parentTag) throws JspException {
48 super.render(pageContext, parentTag);
49
50 JspWriter out = pageContext.getOut();
51 try {
52 out.write(buildDateImage());
53 out.write(buildDateJavascript());
54 }
55 catch (IOException ioe) {
56 throw new JspException("Difficulty rendering date picker", ioe);
57 }
58 }
59
60
61
62
63
64 protected String buildDateImage() {
65 StringBuilder dateImage = new StringBuilder();
66 dateImage.append("<img src=\"");
67 dateImage.append(SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString("kr.externalizable.images.url"));
68 dateImage.append("cal.gif\" ");
69 dateImage.append("id=\"");
70 dateImage.append(getFieldName());
71 dateImage.append("_datepicker\" ");
72 dateImage.append("style=\"cursor: pointer;\" ");
73 dateImage.append("title=\"Date selector for ");
74 dateImage.append(getField().getFieldLabel());
75 dateImage.append("\" ");
76 dateImage.append("alt=\"Date selector for ");
77 dateImage.append(this.getAccessibleTitle());
78 dateImage.append("\" ");
79 dateImage.append("onmouseover=\"this.style.backgroundColor='red';\" ");
80 dateImage.append("onmouseout=\"this.style.backgroundColor='transparent';\"");
81 dateImage.append(" />\n");
82 return dateImage.toString();
83 }
84
85
86
87
88
89 protected String buildDateJavascript() {
90 StringBuilder dateJavascript = new StringBuilder();
91 dateJavascript.append("<script type=\"text/javascript\">\n");
92 dateJavascript.append("Calendar.setup(\n");
93 dateJavascript.append(" {\n");
94 dateJavascript.append(" inputField : \"");
95 dateJavascript.append(getFieldName());
96 dateJavascript.append("\", // ID of the input field\n");
97 dateJavascript.append(" ifFormat : \"%m/%d/%Y\", // the date format\n");
98 dateJavascript.append(" button : \"");
99 dateJavascript.append(getFieldName());
100 dateJavascript.append("_datepicker\" // ID of the button\n");
101 dateJavascript.append(" }\n");
102 dateJavascript.append(");\n");
103 dateJavascript.append("</script>");
104
105 return dateJavascript.toString();
106 }
107
108
109
110
111
112 @Override
113 protected void renderQuickFinderIfNecessary(PageContext pageContext, Tag parentTag) throws JspException {
114
115 }
116
117
118 }