001: /**********************************************************************************
002: * $URL:https://source.sakaiproject.org/svn/osp/trunk/jsf/widgets/src/java/org/theospi/jsf/renderer/TestComponentRenderer.java $
003: * $Id:TestComponentRenderer.java 9134 2006-05-08 20:28:42Z chmaurer@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 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.theospi.jsf.renderer;
021:
022: import java.io.IOException;
023:
024: import javax.faces.component.UIColumn;
025: import javax.faces.component.UIComponent;
026: import javax.faces.component.UIData;
027: import javax.faces.component.UIViewRoot;
028: import javax.faces.component.html.HtmlCommandButton;
029: import javax.faces.component.html.HtmlInputText;
030: import javax.faces.component.html.HtmlOutputLink;
031: import javax.faces.component.html.HtmlOutputText;
032: import javax.faces.context.FacesContext;
033: import javax.faces.context.ResponseWriter;
034: import javax.faces.el.ValueBinding;
035: import javax.faces.event.ActionEvent;
036: import javax.faces.render.Renderer;
037:
038: import org.theospi.jsf.component.TestComponent;
039: import org.theospi.jsf.util.TagUtil;
040:
041: /**
042: * Created by IntelliJ IDEA.
043: * User: John Ellis
044: * Date: Dec 28, 2005
045: * Time: 11:51:38 AM
046: * To change this template use File | Settings | File Templates.
047: */
048: public class TestComponentRenderer extends Renderer {
049:
050: public void decode(FacesContext context, UIComponent component) {
051: super .decode(context, component);
052: }
053:
054: public void encodeBegin(FacesContext context, UIComponent component)
055: throws IOException {
056: super .encodeBegin(context, component);
057: ResponseWriter writer = context.getResponseWriter();
058: writer.write("<b>JDE Test</b>");
059: }
060:
061: public boolean getRendersChildren() {
062: return true;
063: }
064:
065: public void encodeChildren(FacesContext context,
066: UIComponent component) throws IOException {
067: super .encodeChildren(context, component);
068: TestComponent testComponent = (TestComponent) component;
069: UIComponent layoutRoot = testComponent.getLayoutRoot();
070: if (layoutRoot == null) {
071: UIViewRoot root = context.getViewRoot();
072: UIData container = new UIData();
073: ValueBinding vb = context.getApplication()
074: .createValueBinding("#{testBean.subBeans}");
075: container.setValueBinding("value", vb);
076: container.setVar("testSubBean");
077: container.setId(root.createUniqueId());
078: UIColumn column = new UIColumn();
079: column.setId(root.createUniqueId());
080: container.getChildren().add(column);
081: root.getChildren().add(container);
082: HtmlOutputLink testLink = new HtmlOutputLink();
083: testLink.setValue("http://www.javasoft.com");
084: HtmlOutputText text = new HtmlOutputText();
085: text.setValue("test");
086: testLink.getChildren().add(text);
087: HtmlCommandButton button = new HtmlCommandButton();
088: button.setId(root.createUniqueId());
089: button.setActionListener(context.getApplication()
090: .createMethodBinding(
091: "#{testSubBean.processTestButton}",
092: new Class[] { ActionEvent.class }));
093: button.setValue("test me");
094: HtmlInputText input = new HtmlInputText();
095: input.setValueBinding("value", context.getApplication()
096: .createValueBinding("#{testSubBean.index}"));
097: input.setId(root.createUniqueId());
098: column.getChildren().add(input);
099: column.getChildren().add(button);
100: HtmlOutputText testVerbatim = new HtmlOutputText();
101: testVerbatim.setEscape(false);
102: testVerbatim.setValue("<some>");
103: column.getChildren().add(testVerbatim);
104: column.getChildren().add(testLink);
105: HtmlOutputText testVerbatim2 = new HtmlOutputText();
106: testVerbatim2.setEscape(false);
107: testVerbatim2.setValue("</some>");
108: column.getChildren().add(testVerbatim2);
109: TagUtil.renderChild(context, container);
110: testComponent.setLayoutRoot(container);
111: } else {
112: TagUtil.renderChild(context, layoutRoot);
113: }
114: }
115:
116: public void encodeEnd(FacesContext context, UIComponent component)
117: throws IOException {
118: ResponseWriter writer = context.getResponseWriter();
119:
120: writer.write("<b>End JDE Test</b>");
121: super.encodeEnd(context, component);
122: }
123:
124: }
|