View Javadoc

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one
    3    * or more contributor license agreements.  See the NOTICE file
    4    * distributed with this work for additional information
    5    * regarding copyright ownership.  The ASF licenses this file
    6    * to you under the Apache License, Version 2.0 (the
    7    * "License"); you may not use this file except in compliance
    8    * with the License.  You may obtain a copy of the License at
    9    *
    10   *   http://www.apache.org/licenses/LICENSE-2.0
    11   *
    12   * Unless required by applicable law or agreed to in writing,
    13   * software distributed under the License is distributed on an
    14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    15   * KIND, either express or implied.  See the License for the
    16   * specific language governing permissions and limitations
    17   * under the License.
    18   */
    19  package org.apache.myfaces.shared_orchestra.renderkit.html;
    20
    21  import org.apache.myfaces.shared_orchestra.renderkit.RendererUtils;
    22
    23  import javax.faces.component.UIComponent;
    24  import javax.faces.component.UIOutput;
    25  import javax.faces.component.UIInput;
    26  import javax.faces.component.html.HtmlInputTextarea;
    27  import javax.faces.context.FacesContext;
    28  import javax.faces.context.ResponseWriter;
    29  import javax.faces.convert.ConverterException;
    30  import java.io.IOException;
    31
    32
    33  /**
    34   * @author Manfred Geiler (latest modification by $Author: grantsmith $)
    35   * @author Anton Koinov
    36   * @version $Revision: 472618 $ $Date: 2006-11-08 15:06:54 -0500 (Wed, 08 Nov 2006) $
    37   */
    38  public class HtmlTextareaRendererBase
    39          extends HtmlRenderer
    40  {
    41      public void encodeEnd(FacesContext facesContext, UIComponent uiComponent)
    42              throws IOException
    43      {
    44          RendererUtils.checkParamValidity(facesContext, uiComponent, UIInput.class);
    45
    46          encodeTextArea(facesContext, uiComponent);
    47
    48      }
    49
    50      protected void encodeTextArea(FacesContext facesContext, UIComponent uiComponent) throws IOException {
    51          ResponseWriter writer = facesContext.getResponseWriter();
    52          writer.startElement(HTML.TEXTAREA_ELEM, uiComponent);
    53
    54          String clientId = uiComponent.getClientId(facesContext);
    55          writer.writeAttribute(HTML.NAME_ATTR, clientId, null);
    56          HtmlRendererUtils.writeIdIfNecessary(writer, uiComponent, facesContext);
    57
    58          HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.TEXTAREA_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED);
    59          if (isDisabled(facesContext, uiComponent))
    60          {
    61              writer.writeAttribute(org.apache.myfaces.shared_orchestra.renderkit.html.HTML.DISABLED_ATTR, Boolean.TRUE, null);
    62          }
    63
    64          String strValue = org.apache.myfaces.shared_orchestra.renderkit.RendererUtils.getStringValue(facesContext, uiComponent);
    65          writer.writeText(strValue, org.apache.myfaces.shared_orchestra.renderkit.JSFAttr.VALUE_ATTR);
    66
    67          writer.endElement(HTML.TEXTAREA_ELEM);
    68      }
    69
    70      protected boolean isDisabled(FacesContext facesContext, UIComponent uiComponent)
    71      {
    72          //TODO: overwrite in extended HtmlTextareaRenderer and check for enabledOnUserRole
    73          if (uiComponent instanceof HtmlInputTextarea)
    74          {
    75              return ((HtmlInputTextarea)uiComponent).isDisabled();
    76          }
    77          else
    78          {
    79              return org.apache.myfaces.shared_orchestra.renderkit.RendererUtils.getBooleanAttribute(uiComponent, HTML.DISABLED_ATTR, false);
    80          }
    81      }
    82
    83      public void decode(FacesContext facesContext, UIComponent component)
    84      {
    85          RendererUtils.checkParamValidity(facesContext, component, UIInput.class);
    86          HtmlRendererUtils.decodeUIInput(facesContext, component);
    87      }
    88
    89      public Object getConvertedValue(FacesContext facesContext, UIComponent uiComponent, Object submittedValue) throws ConverterException
    90      {
    91          RendererUtils.checkParamValidity(facesContext, uiComponent, UIOutput.class);
    92          return org.apache.myfaces.shared_orchestra.renderkit.RendererUtils.getConvertedUIOutputValue(facesContext,
    93                                                         (UIOutput)uiComponent,
    94                                                         submittedValue);
    95      }
    96
    97  }