001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/sam/tags/sakai_2-4-1/samigo-app/src/java/org/sakaiproject/tool/assessment/jsf/renderer/DatePickerRenderer.java $
003: * $Id: DatePickerRenderer.java 22608 2007-03-14 19:27:17Z lydial@stanford.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.assessment.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: import org.sakaiproject.util.ResourceLoader;
033:
034: import org.sakaiproject.tool.assessment.jsf.renderer.util.RendererUtil;
035:
036: /**
037: * <p>Description: </p>
038: * <p>Render the custom color picker control.</p>
039: * <p>Copyright: Copyright (c) 2004</p>
040: * <p>Organization: Sakai Project</p>
041: * @author Ed Smiley
042: * @version $id: $
043: */
044:
045: public class DatePickerRenderer extends Renderer {
046: // icon height and width
047: private static final String HEIGHT = "16";
048: private static final String WIDTH = "16";
049: private static final String CURSORSTYLE = "cursor:pointer;";
050:
051: //moved to properties
052: //private static final String CLICKALT = "Click Here to Pick Date";
053:
054: private RendererUtil rUtil;
055:
056: public boolean supportsComponentType(UIComponent component) {
057: return (component instanceof UIInput);
058: }
059:
060: /**
061: * decode the value
062: * @param context
063: * @param component
064: */
065: public void decode(FacesContext context, UIComponent component) {
066: // we haven't added these attributes--yet--defensive programming...
067: if (rUtil.isDisabledOrReadonly(component)) {
068: return;
069: }
070:
071: String clientId = component.getClientId(context);
072: Map requestParameterMap = context.getExternalContext()
073: .getRequestParameterMap();
074: String newValue = (String) requestParameterMap.get(clientId);
075: UIInput comp = (UIInput) component;
076: comp.setSubmittedValue(newValue);
077: }
078:
079: public void encodeBegin(FacesContext context, UIComponent component)
080: throws IOException {
081: ;
082: }
083:
084: public void encodeChildren(FacesContext context,
085: UIComponent component) throws IOException {
086: ;
087: }
088:
089: /**
090: * <p>Faces render output method .</p>
091: * <p>Method Generator: org.sakaiproject.tool.assessment.devtoolsRenderMaker</p>
092: *
093: * @param context <code>FacesContext</code> for the current request
094: * @param component <code>UIComponent</code> being rendered
095: *
096: * @throws IOException if an input/output error occurs
097: */
098: public void encodeEnd(FacesContext context, UIComponent component)
099: throws IOException {
100: ResourceLoader rb = new ResourceLoader(
101: "org.sakaiproject.tool.assessment.bundle.AssessmentSettingsMessages");
102: ResponseWriter writer = context.getResponseWriter();
103: String contextPath = context.getExternalContext()
104: .getRequestContextPath();
105:
106: String jsfId = (String) component.getAttributes().get("id");
107: String id = jsfId;
108:
109: if (component.getId() != null
110: && !component.getId().startsWith(
111: UIViewRoot.UNIQUE_ID_PREFIX)) {
112: id = component.getClientId(context);
113: }
114:
115: Object value = null;
116: if (component instanceof UIInput) {
117: value = ((UIInput) component).getSubmittedValue();
118: }
119: if (value == null && component instanceof ValueHolder) {
120: value = ((ValueHolder) component).getValue();
121: }
122: String valString = "";
123: if (value != null) {
124: valString = value.toString();
125: }
126:
127: String type = "text";
128: String size = (String) component.getAttributes().get("size");
129: if (size == null) {
130: size = "20";
131:
132: // script creates unique calendar object with input object
133: }
134: String calRand = "cal" + ("" + Math.random()).substring(2);
135: String calScript = "var " + calRand + " = new calendar2("
136: + "document.getElementById('" + id + "'));" + ""
137: + calRand + ".year_scroll = true;" + "" + calRand
138: + ".time_comp = true;";
139:
140: writer.write("<input type=\"" + type + "\" name=\"" + id
141: + "\" id=\"" + id + "\" size=\"" + size + "\" value=");
142: writer.write("\"" + valString + "\"> <img \n onclick=");
143: writer.write("\"javascript:" + calScript + calRand
144: + ".popup('','" + contextPath + "/html/');\"\n");
145: // "/jsf/widget/datepicker/');\"\n");
146: writer.write(" width=\"" + WIDTH + "\"\n");
147: writer.write(" height=\"" + HEIGHT + "\"\n");
148: writer.write(" style=\"" + CURSORSTYLE + "\" ");
149: writer.write(" src=\"" + contextPath
150: + "/images/calendar/cal.gif\"\n");
151: writer.write(" border=\"0\"\n");
152: writer.write(" id=\"_datePickerPop_" + id + "\"");
153: //writer.write(" alt=\"" + CLICKALT + "\"/>  \n");
154: writer.write(" alt=\"" + rb.getString("dp_CLICKALT")
155: + "\"/>  \n");
156: }
157:
158: }
|