001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/osp/tags/sakai_2-4-1/jsf/widgets/src/java/org/theospi/jsf/renderer/SeparatedListRenderer.java $
003: * $Id: SeparatedListRenderer.java 13032 2006-07-27 19:23:05Z chmaurer@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 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.theospi.jsf.renderer;
021:
022: import java.io.IOException;
023: import java.util.Iterator;
024: import java.util.List;
025:
026: import javax.faces.component.UIComponent;
027: import javax.faces.component.UIOutput;
028: import javax.faces.component.UIViewRoot;
029: import javax.faces.context.FacesContext;
030: import javax.faces.context.ResponseWriter;
031: import javax.faces.render.Renderer;
032:
033: import org.sakaiproject.jsf.util.RendererUtil;
034:
035: public class SeparatedListRenderer extends Renderer {
036:
037: /**
038: * This component renders its children
039: * @return true
040: */
041: public boolean getRendersChildren() {
042: return true;
043: }
044:
045: /**
046: * This is an output type component.
047: * @param component
048: * @return true if UIOutput
049: */
050: public boolean supportsComponentType(UIComponent component) {
051: return (component instanceof UIOutput);
052: }
053:
054: /**
055: * no-op
056: * @param context
057: * @param component
058: * @throws IOException
059: */
060: public void encodeBegin(FacesContext context, UIComponent component)
061: throws IOException {
062: ;
063: }
064:
065: /**
066: * We put all our processing in the encodeChildren method
067: * @param context
068: * @param component
069: * @throws IOException
070: */
071: public void encodeChildren(FacesContext context,
072: UIComponent component) throws IOException {
073: if (!component.isRendered()) {
074: return;
075: }
076:
077: String clientId = null;
078:
079: if (component.getId() != null
080: && !component.getId().startsWith(
081: UIViewRoot.UNIQUE_ID_PREFIX)) {
082: clientId = component.getClientId(context);
083: }
084:
085: ResponseWriter writer = context.getResponseWriter();
086:
087: if (clientId != null) {
088: String styleClass = (String) RendererUtil.getAttribute(
089: context, component, "styleClass");
090: writer.startElement("div", component);
091: writer.writeAttribute("id", clientId, "id");
092: writer.writeAttribute("class", styleClass, "class");
093: }
094:
095: List children = component.getChildren();
096:
097: // this is a special separator attribute, not supported by UIData
098: String separator = (String) RendererUtil.getAttribute(context,
099: component, "separator");
100: if (separator == null)
101: separator = " | ";
102:
103: boolean first = true;
104: for (Iterator iter = children.iterator(); iter.hasNext();) {
105: UIComponent child = (UIComponent) iter.next();
106:
107: if (child.isRendered()) {
108: if (!first)
109: writer.write(separator);
110:
111: RendererUtil.encodeRecursive(context, child);
112: first = false;
113: }
114: }
115: if (clientId != null) {
116: writer.endElement("div");
117: }
118:
119: }
120:
121: /**
122: * no-op
123: * @param context
124: * @param component
125: * @throws IOException
126: */
127: public void encodeEnd(FacesContext context, UIComponent component)
128: throws IOException {
129: ;
130: }
131:
132: }
|