001: /*
002: * Copyright 2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.myfaces.shared_impl.renderkit.html;
017:
018: import org.apache.myfaces.shared_impl.renderkit.RendererUtils;
019: import org.apache.myfaces.shared_impl.renderkit.html.HTML;
020: import org.apache.myfaces.shared_impl.renderkit.html.HtmlRenderer;
021: import org.apache.myfaces.shared_impl.renderkit.html.HtmlRendererUtils;
022:
023: import javax.faces.component.UIComponent;
024: import javax.faces.component.UIInput;
025: import javax.faces.component.UIOutput;
026: import javax.faces.component.html.HtmlInputTextarea;
027: import javax.faces.context.FacesContext;
028: import javax.faces.context.ResponseWriter;
029: import javax.faces.convert.ConverterException;
030: import java.io.IOException;
031:
032: /**
033: * @author Manfred Geiler (latest modification by $Author: dennisbyrne $)
034: * @author Anton Koinov
035: * @version $Revision: 511714 $ $Date: 2007-02-26 05:02:54 +0100 (Mo, 26 Feb 2007) $
036: */
037: public class HtmlTextareaRendererBase extends HtmlRenderer {
038: public void encodeEnd(FacesContext facesContext,
039: UIComponent uiComponent) throws IOException {
040: RendererUtils.checkParamValidity(facesContext, uiComponent,
041: UIInput.class);
042:
043: encodeTextArea(facesContext, uiComponent);
044:
045: }
046:
047: protected void encodeTextArea(FacesContext facesContext,
048: UIComponent uiComponent) throws IOException {
049: ResponseWriter writer = facesContext.getResponseWriter();
050: writer.startElement(HTML.TEXTAREA_ELEM, uiComponent);
051:
052: String clientId = uiComponent.getClientId(facesContext);
053: writer.writeAttribute(HTML.NAME_ATTR, clientId, null);
054: HtmlRendererUtils.writeIdIfNecessary(writer, uiComponent,
055: facesContext);
056:
057: HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent,
058: HTML.TEXTAREA_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED);
059: if (isDisabled(facesContext, uiComponent)) {
060: writer
061: .writeAttribute(
062: org.apache.myfaces.shared_impl.renderkit.html.HTML.DISABLED_ATTR,
063: Boolean.TRUE, null);
064: }
065:
066: String strValue = org.apache.myfaces.shared_impl.renderkit.RendererUtils
067: .getStringValue(facesContext, uiComponent);
068: writer
069: .writeText(
070: strValue,
071: org.apache.myfaces.shared_impl.renderkit.JSFAttr.VALUE_ATTR);
072:
073: writer.endElement(HTML.TEXTAREA_ELEM);
074: }
075:
076: protected boolean isDisabled(FacesContext facesContext,
077: UIComponent uiComponent) {
078: //TODO: overwrite in extended HtmlTextareaRenderer and check for enabledOnUserRole
079: if (uiComponent instanceof HtmlInputTextarea) {
080: return ((HtmlInputTextarea) uiComponent).isDisabled();
081: }
082:
083: return org.apache.myfaces.shared_impl.renderkit.RendererUtils
084: .getBooleanAttribute(uiComponent, HTML.DISABLED_ATTR,
085: false);
086:
087: }
088:
089: public void decode(FacesContext facesContext, UIComponent component) {
090: RendererUtils.checkParamValidity(facesContext, component,
091: UIInput.class);
092: HtmlRendererUtils.decodeUIInput(facesContext, component);
093: }
094:
095: public Object getConvertedValue(FacesContext facesContext,
096: UIComponent uiComponent, Object submittedValue)
097: throws ConverterException {
098: RendererUtils.checkParamValidity(facesContext, uiComponent,
099: UIOutput.class);
100: return org.apache.myfaces.shared_impl.renderkit.RendererUtils
101: .getConvertedUIOutputValue(facesContext,
102: (UIOutput) uiComponent, submittedValue);
103: }
104:
105: }
|