Coverage Report - org.apache.myfaces.shared.renderkit.html.HtmlTextareaRendererBase
 
Classes in this File Line Coverage Branch Coverage Complexity
HtmlTextareaRendererBase
0%
0/77
0%
0/38
3.5
 
 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 java.io.IOException;
 22  
 import java.util.List;
 23  
 import java.util.Map;
 24  
 
 25  
 import javax.faces.component.UIComponent;
 26  
 import javax.faces.component.UIInput;
 27  
 import javax.faces.component.UIOutput;
 28  
 import javax.faces.component.behavior.ClientBehavior;
 29  
 import javax.faces.component.behavior.ClientBehaviorHolder;
 30  
 import javax.faces.component.html.HtmlInputTextarea;
 31  
 import javax.faces.context.FacesContext;
 32  
 import javax.faces.context.ResponseWriter;
 33  
 import javax.faces.convert.ConverterException;
 34  
 
 35  
 import org.apache.myfaces.shared.renderkit.RendererUtils;
 36  
 import org.apache.myfaces.shared.renderkit.html.util.ResourceUtils;
 37  
 
 38  
 
 39  0
 public class HtmlTextareaRendererBase
 40  
         extends HtmlRenderer
 41  
 {
 42  
     private static final String ADD_NEW_LINE_AT_START_ATTR = "org.apache.myfaces.addNewLineAtStart";
 43  
     
 44  
     public void encodeEnd(FacesContext facesContext, UIComponent uiComponent)
 45  
             throws IOException
 46  
     {
 47  0
         RendererUtils.checkParamValidity(facesContext, uiComponent, UIInput.class);
 48  
 
 49  0
         Map<String, List<ClientBehavior>> behaviors = null;
 50  0
         if (uiComponent instanceof ClientBehaviorHolder)
 51  
         {
 52  0
             behaviors = ((ClientBehaviorHolder) uiComponent).getClientBehaviors();
 53  0
             if (!behaviors.isEmpty())
 54  
             {
 55  0
                 ResourceUtils.renderDefaultJsfJsInlineIfNecessary(facesContext, 
 56  
                         facesContext.getResponseWriter());
 57  
             }
 58  
         }
 59  
         
 60  0
         encodeTextArea(facesContext, uiComponent);
 61  
 
 62  0
     }
 63  
 
 64  
     protected void encodeTextArea(FacesContext facesContext, UIComponent uiComponent) 
 65  
         throws IOException
 66  
     {
 67  
        //allow subclasses to render custom attributes by separating rendering begin and end
 68  0
         renderTextAreaBegin(facesContext, uiComponent);
 69  0
         renderTextAreaValue(facesContext, uiComponent);
 70  0
         renderTextAreaEnd(facesContext, uiComponent);
 71  
         
 72  0
     }
 73  
 
 74  
     //Subclasses can set the value of an attribute before, or can render a custom attribute after calling this method
 75  
     protected void renderTextAreaBegin(FacesContext facesContext,
 76  
             UIComponent uiComponent) throws IOException
 77  
     {
 78  0
         ResponseWriter writer = facesContext.getResponseWriter();
 79  0
         writer.startElement(HTML.TEXTAREA_ELEM, uiComponent);
 80  
 
 81  0
         Map<String, List<ClientBehavior>> behaviors = null;
 82  0
         if (uiComponent instanceof ClientBehaviorHolder)
 83  
         {
 84  0
             behaviors = ((ClientBehaviorHolder) uiComponent).getClientBehaviors();
 85  0
             if (!behaviors.isEmpty())
 86  
             {
 87  0
                 HtmlRendererUtils.writeIdAndName(writer, uiComponent, facesContext);
 88  
             }
 89  
             else
 90  
             {
 91  0
                 HtmlRendererUtils.writeIdIfNecessary(writer, uiComponent, facesContext);
 92  0
                 writer.writeAttribute(HTML.NAME_ATTR, uiComponent.getClientId(facesContext), null);
 93  
             }
 94  0
             long commonPropertiesMarked = 0L;
 95  0
             if (isCommonPropertiesOptimizationEnabled(facesContext))
 96  
             {
 97  0
                 commonPropertiesMarked = CommonPropertyUtils.getCommonPropertiesMarked(uiComponent);
 98  
             }
 99  0
             if (behaviors.isEmpty() && isCommonPropertiesOptimizationEnabled(facesContext))
 100  
             {
 101  0
                 CommonPropertyUtils.renderChangeEventProperty(writer, 
 102  
                         commonPropertiesMarked, uiComponent);
 103  0
                 CommonPropertyUtils.renderEventProperties(writer, 
 104  
                         commonPropertiesMarked, uiComponent);
 105  0
                 CommonPropertyUtils.renderFieldEventPropertiesWithoutOnchange(writer, 
 106  
                         commonPropertiesMarked, uiComponent);
 107  
             }
 108  
             else
 109  
             {
 110  0
                 HtmlRendererUtils.renderBehaviorizedOnchangeEventHandler(facesContext, writer, uiComponent, behaviors);
 111  0
                 if (isCommonEventsOptimizationEnabled(facesContext))
 112  
                 {
 113  0
                     Long commonEventsMarked = CommonEventUtils.getCommonEventsMarked(uiComponent);
 114  0
                     CommonEventUtils.renderBehaviorizedEventHandlers(facesContext, writer, 
 115  
                             commonPropertiesMarked, commonEventsMarked, uiComponent, behaviors);
 116  0
                     CommonEventUtils.renderBehaviorizedFieldEventHandlersWithoutOnchange(
 117  
                         facesContext, writer, commonPropertiesMarked, commonEventsMarked, uiComponent, behaviors);
 118  0
                 }
 119  
                 else
 120  
                 {
 121  0
                     HtmlRendererUtils.renderBehaviorizedEventHandlers(facesContext, writer, uiComponent, behaviors);
 122  0
                     HtmlRendererUtils.renderBehaviorizedFieldEventHandlersWithoutOnchange(
 123  
                             facesContext, writer, uiComponent, behaviors);
 124  
                 }
 125  
             }
 126  0
             if (isCommonPropertiesOptimizationEnabled(facesContext))
 127  
             {
 128  0
                 CommonPropertyUtils.renderCommonFieldPassthroughPropertiesWithoutDisabledAndEvents(writer, 
 129  
                         CommonPropertyUtils.getCommonPropertiesMarked(uiComponent), uiComponent);
 130  0
                 HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.TEXTAREA_ATTRIBUTES);
 131  
             }
 132  
             else
 133  
             {
 134  0
                 HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, 
 135  
                         HTML.TEXTAREA_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED_AND_EVENTS);
 136  
             }
 137  0
         }
 138  
         else
 139  
         {
 140  0
             HtmlRendererUtils.writeIdIfNecessary(writer, uiComponent, facesContext);
 141  0
             writer.writeAttribute(HTML.NAME_ATTR, uiComponent.getClientId(facesContext), null);
 142  0
             if (isCommonPropertiesOptimizationEnabled(facesContext))
 143  
             {
 144  0
                 CommonPropertyUtils.renderCommonFieldPassthroughPropertiesWithoutDisabled(writer, 
 145  
                         CommonPropertyUtils.getCommonPropertiesMarked(uiComponent), uiComponent);
 146  0
                 HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.TEXTAREA_ATTRIBUTES);
 147  
             }
 148  
             else
 149  
             {
 150  0
                 HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, 
 151  
                         HTML.TEXTAREA_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED);
 152  
             }
 153  
         }
 154  
 
 155  0
         if (isDisabled(facesContext, uiComponent))
 156  
         {
 157  0
             writer.writeAttribute(org.apache.myfaces.shared.renderkit.html.HTML.DISABLED_ATTR, Boolean.TRUE, null);
 158  
         }
 159  0
     }
 160  
 
 161  
     //Subclasses can override the writing of the "text" value of the textarea
 162  
     protected void renderTextAreaValue(FacesContext facesContext, UIComponent uiComponent) throws IOException
 163  
     {
 164  0
         ResponseWriter writer = facesContext.getResponseWriter();
 165  
         
 166  0
         Object addNewLineAtStart = uiComponent.getAttributes().get(ADD_NEW_LINE_AT_START_ATTR);
 167  0
         if (addNewLineAtStart != null)
 168  
         {
 169  0
             boolean addNewLineAtStartBoolean = false;
 170  0
             if (addNewLineAtStart instanceof String)
 171  
             {
 172  0
                 addNewLineAtStartBoolean = Boolean.valueOf((String)addNewLineAtStart);
 173  
             }
 174  0
             else if (addNewLineAtStart instanceof Boolean)
 175  
             {
 176  0
                 addNewLineAtStartBoolean = (Boolean) addNewLineAtStart;
 177  
             }
 178  0
             if (addNewLineAtStartBoolean)
 179  
             {
 180  0
                 writer.writeText("\n", null);
 181  
             }
 182  
         }
 183  
         
 184  0
         String strValue = org.apache.myfaces.shared.renderkit.RendererUtils.getStringValue(facesContext, uiComponent);
 185  0
         if (strValue != null)
 186  
         {
 187  0
             writer.writeText(strValue, org.apache.myfaces.shared.renderkit.JSFAttr.VALUE_ATTR);
 188  
         }
 189  0
     }
 190  
     
 191  
     protected void renderTextAreaEnd(FacesContext facesContext,
 192  
             UIComponent uiComponent) throws IOException
 193  
     {
 194  0
         facesContext.getResponseWriter().endElement(HTML.TEXTAREA_ELEM);
 195  0
     }
 196  
     
 197  
     protected boolean isDisabled(FacesContext facesContext, UIComponent uiComponent)
 198  
     {
 199  
         //TODO: overwrite in extended HtmlTextareaRenderer and check for enabledOnUserRole
 200  0
         if (uiComponent instanceof HtmlInputTextarea)
 201  
         {
 202  0
             return ((HtmlInputTextarea)uiComponent).isDisabled();
 203  
         }
 204  
 
 205  0
         return org.apache.myfaces.shared.renderkit.RendererUtils.getBooleanAttribute(
 206  
                 uiComponent, HTML.DISABLED_ATTR, false);
 207  
         
 208  
     }
 209  
 
 210  
     public void decode(FacesContext facesContext, UIComponent component)
 211  
     {
 212  0
         RendererUtils.checkParamValidity(facesContext, component, UIInput.class);
 213  0
         HtmlRendererUtils.decodeUIInput(facesContext, component);
 214  0
         if (component instanceof ClientBehaviorHolder &&
 215  
             !HtmlRendererUtils.isDisabled(component))
 216  
         {
 217  0
             HtmlRendererUtils.decodeClientBehaviors(facesContext, component);
 218  
         }
 219  0
     }
 220  
 
 221  
     public Object getConvertedValue(FacesContext facesContext, UIComponent uiComponent, Object submittedValue)
 222  
         throws ConverterException
 223  
     {
 224  0
         RendererUtils.checkParamValidity(facesContext, uiComponent, UIOutput.class);
 225  0
         return org.apache.myfaces.shared.renderkit.RendererUtils.getConvertedUIOutputValue(facesContext,
 226  
                                                        (UIOutput)uiComponent,
 227  
                                                        submittedValue);
 228  
     }
 229  
 
 230  
 }