001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/jsf/tags/sakai_2-4-1/widgets/src/java/org/sakaiproject/jsf/renderer/DataLineRenderer.java $
003: * $Id: DataLineRenderer.java 9278 2006-05-10 23:29:21Z ray@media.berkeley.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2003, 2004 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.jsf.renderer;
021:
022: import java.io.IOException;
023: import java.util.Iterator;
024: import javax.faces.component.UIColumn;
025: import javax.faces.component.UIComponent;
026: import javax.faces.component.UIData;
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: /**
036: * <p>Description: </p>
037: * <p>Render a iterated data like a dataTable but without the table.</p>
038: * <p> Based on example code by from the O'Reilley JSF book. </p>
039: * <p>Copyright: Copyright (c) 2004</p>
040: * <p>Organization: Sakai Project</p>
041: * @author Ed Smiley
042: * @version $Id: DataLineRenderer.java 9278 2006-05-10 23:29:21Z ray@media.berkeley.edu $
043: */
044:
045: public class DataLineRenderer extends Renderer {
046:
047: /**
048: * This component renders its children
049: * @return true
050: */
051: public boolean getRendersChildren() {
052: return true;
053: }
054:
055: /**
056: * This is an output type component.
057: * @param component
058: * @return true if UIOutput
059: */
060: public boolean supportsComponentType(UIComponent component) {
061: return (component instanceof UIOutput);
062: }
063:
064: /**
065: * no-op
066: * @param context
067: * @param component
068: * @throws IOException
069: */
070: public void encodeBegin(FacesContext context, UIComponent component)
071: throws IOException {
072: ;
073: }
074:
075: /**
076: * We put all our processing in the encodeChildren method
077: * @param context
078: * @param component
079: * @throws IOException
080: */
081: public void encodeChildren(FacesContext context,
082: UIComponent component) throws IOException {
083: if (!component.isRendered()) {
084: return;
085: }
086:
087: String clientId = null;
088:
089: if (component.getId() != null
090: && !component.getId().startsWith(
091: UIViewRoot.UNIQUE_ID_PREFIX)) {
092: clientId = component.getClientId(context);
093: }
094:
095: ResponseWriter writer = context.getResponseWriter();
096:
097: if (clientId != null) {
098: writer.startElement("span", component);
099: writer.writeAttribute("id", clientId, "id");
100: }
101:
102: UIData data = (UIData) component;
103:
104: int first = data.getFirst();
105: int rows = data.getRows();
106:
107: // this is a special separator attribute, not supported by UIData
108: String separator = (String) RendererUtil.getAttribute(context,
109: component, "separator");
110: if (separator == null)
111: separator = " | ";
112:
113: for (int i = first, n = 0; n < rows; i++, n++) {
114: data.setRowIndex(i);
115: if (!data.isRowAvailable()) {
116: break;
117: }
118:
119: // between any two iterations add separator if there is one
120: if (i != first)
121: writer.write(separator);
122:
123: Iterator iter = data.getChildren().iterator();
124: while (iter.hasNext()) {
125: UIComponent column = (UIComponent) iter.next();
126: if (!(column instanceof UIColumn)) {
127: continue;
128: }
129: RendererUtil.encodeRecursive(context, column);
130: }
131: }
132: if (clientId != null) {
133: writer.endElement("span");
134: }
135:
136: }
137:
138: /**
139: * no-op
140: * @param context
141: * @param component
142: * @throws IOException
143: */
144: public void encodeEnd(FacesContext context, UIComponent component)
145: throws IOException {
146: ;
147: }
148:
149: }
|