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