01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/osp/tags/sakai_2-4-1/jsf/widgets/src/java/org/theospi/jsf/renderer/FormLabelRenderer.java $
03: * $Id: FormLabelRenderer.java 15703 2006-10-05 18:16:51Z chmaurer@iupui.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2005, 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.theospi.jsf.renderer;
21:
22: import java.io.IOException;
23:
24: import javax.faces.component.UIComponent;
25: import javax.faces.component.UIOutput;
26: import javax.faces.context.FacesContext;
27: import javax.faces.context.ResponseWriter;
28: import javax.faces.render.Renderer;
29:
30: import org.sakaiproject.jsf.util.RendererUtil;
31: import org.theospi.jsf.util.ConfigurationResource;
32:
33: public class FormLabelRenderer extends Renderer {
34:
35: private static final String RESOURCE_PATH;
36: private static final String REQ_CHAR;
37: private static final String CSS_LOC;
38:
39: static {
40: ConfigurationResource cr = new ConfigurationResource();
41: RESOURCE_PATH = "/" + cr.get("resources");
42: REQ_CHAR = cr.get("req_field_char");
43: CSS_LOC = RESOURCE_PATH + "/" + cr.get("cssFile");
44: }
45:
46: public boolean supportsComponentType(UIComponent component) {
47: return (component instanceof UIOutput);
48: }
49:
50: /**
51: * This renders html for the beginning of the tag.
52: *
53: * @param context
54: * @param component
55: * @throws IOException
56: */
57: public void encodeBegin(FacesContext context, UIComponent component)
58: throws IOException {
59: ResponseWriter writer = context.getResponseWriter();
60: String valueRequired = (String) RendererUtil.getAttribute(
61: context, component, "valueRequired");
62: String displayCharOnRight = (String) RendererUtil.getAttribute(
63: context, component, "displayCharOnRight");
64: if (valueRequired.equalsIgnoreCase("true")
65: && !displayCharOnRight.equalsIgnoreCase("true")) {
66: writeReqChar(context, writer);
67: }
68: }
69:
70: /**
71: * @param context FacesContext for the request we are processing
72: * @param component UIComponent to be rendered
73: * @exception IOException if an input/output error occurs while rendering
74: * @exception NullPointerException if <code>context</code> or <code>component</code> is null
75: */
76: public void encodeEnd(FacesContext context, UIComponent component)
77: throws IOException {
78: ResponseWriter writer = context.getResponseWriter();
79: String valueRequired = (String) RendererUtil.getAttribute(
80: context, component, "valueRequired");
81: String displayCharOnRight = (String) RendererUtil.getAttribute(
82: context, component, "displayCharOnRight");
83:
84: if (valueRequired.equalsIgnoreCase("true")
85: && displayCharOnRight.equalsIgnoreCase("true")) {
86: writeReqChar(context, writer);
87: }
88: }
89:
90: protected void writeReqChar(FacesContext context,
91: ResponseWriter writer) throws IOException {
92: RendererUtil.writeExternalCSSDependencies(context, writer,
93: "osp.jsf.css", CSS_LOC);
94: writer.write("<span class=\"osp_required_field\">");
95: writer.write(REQ_CHAR);
96: writer.write("</span>");
97: }
98:
99: }
|