001: /*
002: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
003: *
004: * "The contents of this file are subject to the Mozilla Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License at
007: * http://www.mozilla.org/MPL/
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
011: * License for the specific language governing rights and limitations under
012: * the License.
013: *
014: * The Original Code is ICEfaces 1.5 open source software code, released
015: * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
016: * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
017: * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
018: *
019: * Contributor(s): _____________________.
020: *
021: * Alternatively, the contents of this file may be used under the terms of
022: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
023: * License), in which case the provisions of the LGPL License are
024: * applicable instead of those above. If you wish to allow use of your
025: * version of this file only under the terms of the LGPL License and not to
026: * allow others to use your version of this file under the MPL, indicate
027: * your decision by deleting the provisions above and replace them with
028: * the notice and other provisions required by the LGPL License. If you do
029: * not delete the provisions above, a recipient may use your version of
030: * this file under either the MPL or the LGPL License."
031: *
032: */
033:
034: package com.icesoft.faces.component.panelseries;
035:
036: import com.icesoft.faces.context.DOMContext;
037: import com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer;
038: import com.icesoft.faces.renderkit.dom_html_basic.HTML;
039: import org.w3c.dom.Element;
040:
041: import javax.faces.component.UIComponent;
042: import javax.faces.context.FacesContext;
043: import java.io.IOException;
044: import java.util.Iterator;
045:
046: public class PanelSeriesRenderer extends DomBasicRenderer {
047: public boolean getRendersChildren() {
048: return true;
049: }
050:
051: public void encodeBegin(FacesContext facesContext,
052: UIComponent uiComponent) throws IOException {
053: DOMContext domContext = DOMContext.attachDOMContext(
054: facesContext, uiComponent);
055:
056: if (!domContext.isInitialized()) {
057: Element rootSpan = domContext.createElement(HTML.DIV_ELEM);
058: domContext.setRootNode(rootSpan);
059: setRootElementId(facesContext, rootSpan, uiComponent);
060: }
061: Element root = (Element) domContext.getRootNode();
062: String style = ((PanelSeries) uiComponent).getStyle();
063: if (style != null && style.length() > 0)
064: root.setAttribute(HTML.STYLE_ATTR, style);
065: else
066: root.removeAttribute(HTML.STYLE_ATTR);
067: root.setAttribute(HTML.CLASS_ATTR, ((PanelSeries) uiComponent)
068: .getStyleClass());
069: domContext.stepInto(uiComponent);
070: }
071:
072: public void encodeChildren(FacesContext facesContext,
073: UIComponent uiComponent) throws IOException {
074: validateParameters(facesContext, uiComponent, null);
075: DOMContext domContext = DOMContext.attachDOMContext(
076: facesContext, uiComponent);
077: Element root = (Element) domContext.getRootNode();
078: DOMContext.removeChildren(root);
079: PanelSeries list = (PanelSeries) uiComponent;
080: UISeries uiList = (UISeries) uiComponent;
081: int rowIndex = uiList.getFirst();
082: uiList.setRowIndex(rowIndex);
083: int numberOfRowsToDisplay = uiList.getRows();
084: int countOfRowsDisplayed = 0;
085: while (uiList.isRowAvailable()) {
086: if ((numberOfRowsToDisplay > 0)
087: && (countOfRowsDisplayed >= numberOfRowsToDisplay)) {
088: break;
089: }
090: Iterator childs;
091: childs = list.getChildren().iterator();
092: while (childs.hasNext()) {
093: UIComponent nextChild = (UIComponent) childs.next();
094: if (nextChild.isRendered()) {
095: domContext.setCursorParent(root);
096: domContext.streamWrite(facesContext, uiComponent,
097: domContext.getRootNode(), root);
098: encodeParentAndChildren(facesContext, nextChild);
099: }
100: }
101: rowIndex++;
102: countOfRowsDisplayed++;
103: uiList.setRowIndex(rowIndex);
104: }
105: uiList.setRowIndex(-1);
106:
107: }
108: }
|