001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/podcasts/tags/sakai_2-4-1/podcasts-app/src/java/org/sakaiproject/tool/podcasts/jsf/renderer/DatePickerRenderer.java $
003: * $Id: DatePickerRenderer.java 14691 2006-09-15 12:36:27Z ajpoland@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the"License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.tool.podcasts.jsf.renderer;
021:
022: import java.io.IOException;
023: import java.util.Map;
024:
025: import javax.faces.component.UIComponent;
026: import javax.faces.component.UIInput;
027: import javax.faces.component.UIViewRoot;
028: import javax.faces.component.ValueHolder;
029: import javax.faces.context.FacesContext;
030: import javax.faces.context.ResponseWriter;
031: import javax.faces.render.Renderer;
032:
033: import org.sakaiproject.tool.podcasts.jsf.renderer.util.RendererUtil;
034:
035: /**
036: * <p>Description: </p>
037: * <p>Render the custom color picker control.</p>
038: * <p>Copyright: Copyright (c) 2004</p>
039: * <p>Organization: Sakai Project</p>
040: * @author Ed Smiley
041: * @version $id: $
042: */
043:
044: public class DatePickerRenderer extends Renderer {
045: // icon height and width
046: private static final String HEIGHT = "16";
047: private static final String WIDTH = "16";
048: private static final String CURSORSTYLE = "cursor:pointer;";
049: private static final String CLICKALT = "Click Here to Pick Date";
050:
051: private RendererUtil rUtil;
052:
053: public boolean supportsComponentType(UIComponent component) {
054: return (component instanceof UIInput);
055: }
056:
057: /**
058: * decode the value
059: * @param context
060: * @param component
061: */
062: public void decode(FacesContext context, UIComponent component) {
063: // we haven't added these attributes--yet--defensive programming...
064: if (rUtil.isDisabledOrReadonly(component)) {
065: return;
066: }
067:
068: String clientId = component.getClientId(context);
069: Map requestParameterMap = context.getExternalContext()
070: .getRequestParameterMap();
071: String newValue = (String) requestParameterMap.get(clientId);
072:
073: UIInput comp = (UIInput) component;
074: comp.setSubmittedValue(newValue);
075: }
076:
077: public void encodeBegin(FacesContext context, UIComponent component)
078: throws IOException {
079: ;
080: }
081:
082: public void encodeChildren(FacesContext context,
083: UIComponent component) throws IOException {
084: ;
085: }
086:
087: /**
088: * <p>Faces render output method .</p>
089: * <p>Method Generator: org.sakaiproject.tool.assessment.devtoolsRenderMaker</p>
090: *
091: * @param context <code>FacesContext</code> for the current request
092: * @param component <code>UIComponent</code> being rendered
093: *
094: * @throws IOException if an input/output error occurs
095: */
096: public void encodeEnd(FacesContext context, UIComponent component)
097: throws IOException {
098: ResponseWriter writer = context.getResponseWriter();
099: String contextPath = context.getExternalContext()
100: .getRequestContextPath();
101:
102: String jsfId = (String) component.getAttributes().get("id");
103: String id = jsfId;
104:
105: if (component.getId() != null
106: && !component.getId().startsWith(
107: UIViewRoot.UNIQUE_ID_PREFIX)) {
108: id = component.getClientId(context);
109: }
110:
111: Object value = null;
112: if (component instanceof UIInput) {
113: value = ((UIInput) component).getSubmittedValue();
114: }
115: if (value == null && component instanceof ValueHolder) {
116: value = ((ValueHolder) component).getValue();
117: }
118: String valString = "";
119: if (value != null) {
120: valString = value.toString();
121: }
122:
123: String type = "text";
124: String size = (String) component.getAttributes().get("size");
125: if (size == null) {
126: size = "28";
127:
128: // script creates unique calendar object with input object
129: }
130: String calRand = "cal" + ("" + Math.random()).substring(2);
131: String calScript = "var " + calRand + " = new calendar2("
132: + "document.getElementById('" + id + "'));" + ""
133: + calRand + ".year_scroll = true;" + "" + calRand
134: + ".time_comp = true;";
135:
136: writer.write("<input type=\"" + type + "\" name=\"" + id
137: + "\" id=\"" + id + "\" size=\"" + size + "\" value=");
138: writer.write("\"" + valString + "\"> <img \n onclick=");
139: writer.write("\"javascript:" + calScript + calRand
140: + ".popup('','" + contextPath + "/html/');\"\n");
141: // "/jsf/widget/datepicker/');\"\n");
142: writer.write(" width=\"" + WIDTH + "\"\n");
143: writer.write(" height=\"" + HEIGHT + "\"\n");
144: writer.write(" style=\"" + CURSORSTYLE + "\" ");
145: writer.write(" src=\"" + contextPath
146: + "/images/calendar/cal.gif\"\n");
147: writer.write(" border=\"0\"\n");
148: writer.write(" id=\"_datePickerPop_" + id + "\"");
149: writer.write(" alt=\"" + CLICKALT + "\"/>  \n");
150: }
151:
152: }
|