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.renderkit.html;
20  
21  import org.apache.myfaces.shared.renderkit.RendererUtils;
22  import org.apache.myfaces.shared.renderkit.html.HTML;
23  import org.apache.myfaces.shared.renderkit.html.HtmlRenderer;
24  import org.apache.myfaces.shared.renderkit.html.HtmlRendererUtils;
25  
26  import javax.faces.component.UIComponent;
27  import javax.faces.component.UIInput;
28  import javax.faces.component.UIOutput;
29  import javax.faces.component.html.HtmlInputTextarea;
30  import javax.faces.context.FacesContext;
31  import javax.faces.context.ResponseWriter;
32  import javax.faces.convert.ConverterException;
33  import java.io.IOException;
34  
35  
36  /***
37   * @author Manfred Geiler (latest modification by $Author: matzew $)
38   * @author Anton Koinov
39   * @version $Revision: 557350 $ $Date: 2007-07-18 13:19:50 -0500 (Wed, 18 Jul 2007) $
40   */
41  public class HtmlTextareaRendererBase
42          extends HtmlRenderer
43  {
44      public void encodeEnd(FacesContext facesContext, UIComponent uiComponent)
45              throws IOException
46      {
47          RendererUtils.checkParamValidity(facesContext, uiComponent, UIInput.class);
48  
49          encodeTextArea(facesContext, uiComponent);
50  
51      }
52  
53      protected void encodeTextArea(FacesContext facesContext, UIComponent uiComponent) throws IOException {
54          ResponseWriter writer = facesContext.getResponseWriter();
55          writer.startElement(HTML.TEXTAREA_ELEM, uiComponent);
56  
57          String clientId = uiComponent.getClientId(facesContext);
58          writer.writeAttribute(HTML.NAME_ATTR, clientId, null);
59          HtmlRendererUtils.writeIdIfNecessary(writer, uiComponent, facesContext);
60  
61          HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.TEXTAREA_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED);
62          if (isDisabled(facesContext, uiComponent))
63          {
64              writer.writeAttribute(org.apache.myfaces.shared.renderkit.html.HTML.DISABLED_ATTR, Boolean.TRUE, null);
65          }
66  
67          String strValue = org.apache.myfaces.shared.renderkit.RendererUtils.getStringValue(facesContext, uiComponent);
68          writer.writeText(strValue, org.apache.myfaces.shared.renderkit.JSFAttr.VALUE_ATTR);
69  
70          writer.endElement(HTML.TEXTAREA_ELEM);
71      }
72  
73      protected boolean isDisabled(FacesContext facesContext, UIComponent uiComponent)
74      {
75          //TODO: overwrite in extended HtmlTextareaRenderer and check for enabledOnUserRole
76          if (uiComponent instanceof HtmlInputTextarea)
77          {
78              return ((HtmlInputTextarea)uiComponent).isDisabled();
79          }
80  
81          return org.apache.myfaces.shared.renderkit.RendererUtils.getBooleanAttribute(uiComponent, HTML.DISABLED_ATTR, false);
82          
83      }
84  
85      public void decode(FacesContext facesContext, UIComponent component)
86      {
87          RendererUtils.checkParamValidity(facesContext, component, UIInput.class);
88          HtmlRendererUtils.decodeUIInput(facesContext, component);
89      }
90  
91      public Object getConvertedValue(FacesContext facesContext, UIComponent uiComponent, Object submittedValue) throws ConverterException
92      {
93          RendererUtils.checkParamValidity(facesContext, uiComponent, UIOutput.class);
94          return org.apache.myfaces.shared.renderkit.RendererUtils.getConvertedUIOutputValue(facesContext,
95                                                         (UIOutput)uiComponent,
96                                                         submittedValue);
97      }
98  
99  }