Coverage Report - org.apache.myfaces.shared.renderkit.html.HtmlListboxRendererBase
 
Classes in this File Line Coverage Branch Coverage Complexity
HtmlListboxRendererBase
0%
0/45
0%
0/30
4.429
 
 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.JSFAttr;
 22  
 import org.apache.myfaces.shared.renderkit.RendererUtils;
 23  
 import org.apache.myfaces.shared.renderkit.html.util.ResourceUtils;
 24  
 
 25  
 import javax.faces.component.UIComponent;
 26  
 import javax.faces.component.UISelectMany;
 27  
 import javax.faces.component.UISelectOne;
 28  
 import javax.faces.component.behavior.ClientBehavior;
 29  
 import javax.faces.component.behavior.ClientBehaviorHolder;
 30  
 import javax.faces.component.html.HtmlSelectManyListbox;
 31  
 import javax.faces.component.html.HtmlSelectOneListbox;
 32  
 import javax.faces.context.FacesContext;
 33  
 import javax.faces.convert.Converter;
 34  
 import javax.faces.convert.ConverterException;
 35  
 import java.io.IOException;
 36  
 import java.util.List;
 37  
 import java.util.Map;
 38  
 
 39  
 
 40  0
 public class HtmlListboxRendererBase
 41  
         extends HtmlSelectableRendererBase
 42  
 {
 43  
     public void encodeEnd(FacesContext facesContext, UIComponent uiComponent)
 44  
             throws IOException
 45  
     {
 46  0
         org.apache.myfaces.shared.renderkit.RendererUtils.checkParamValidity(facesContext, uiComponent, null);
 47  
         
 48  0
         Map<String, List<ClientBehavior>> behaviors = null;
 49  0
         if (uiComponent instanceof ClientBehaviorHolder)
 50  
         {
 51  0
             behaviors = ((ClientBehaviorHolder) uiComponent).getClientBehaviors();
 52  0
             if (!behaviors.isEmpty())
 53  
             {
 54  0
                 ResourceUtils.renderDefaultJsfJsInlineIfNecessary(
 55  
                         facesContext, facesContext.getResponseWriter());
 56  
             }
 57  
         }
 58  
 
 59  0
         Integer size = (Integer)uiComponent.getAttributes().get(JSFAttr.SIZE_ATTR);
 60  0
         if (size == null)
 61  
         {
 62  0
             size = Integer.MIN_VALUE;
 63  
         }
 64  
 
 65  0
         if (uiComponent instanceof UISelectMany)
 66  
         {
 67  0
             renderListbox(facesContext,
 68  
                                             (UISelectMany)uiComponent,
 69  
                                             isDisabled(facesContext, uiComponent),
 70  
                                             size, getConverter(facesContext, uiComponent));
 71  
         }
 72  0
         else if (uiComponent instanceof HtmlSelectOneListbox)
 73  
         {
 74  0
             renderListbox(facesContext,
 75  
                                             (UISelectOne)uiComponent,
 76  
                                             isDisabled(facesContext, uiComponent),
 77  
                                             size, getConverter(facesContext, uiComponent));
 78  
         }
 79  
         else
 80  
         {
 81  0
             throw new IllegalArgumentException("Unsupported component class " + uiComponent.getClass().getName());
 82  
         }
 83  0
     }
 84  
     
 85  
     protected void renderListbox(FacesContext facesContext,
 86  
             UISelectOne selectOne, boolean disabled, int size,
 87  
             Converter converter) throws IOException
 88  
     {
 89  0
         internalRenderSelect(facesContext, selectOne, disabled, size, false,
 90  
                 converter);
 91  0
     }
 92  
 
 93  
     protected void renderListbox(FacesContext facesContext,
 94  
             UISelectMany selectMany, boolean disabled, int size,
 95  
             Converter converter) throws IOException
 96  
     {
 97  0
         internalRenderSelect(facesContext, selectMany, disabled, size, true,
 98  
                 converter);
 99  0
     }
 100  
 
 101  
     protected boolean isDisabled(FacesContext facesContext, UIComponent uiComponent)
 102  
     {
 103  
         //TODO: overwrite in extended HtmlListboxRenderer and check for enabledOnUserRole
 104  0
         if (uiComponent instanceof HtmlSelectManyListbox)
 105  
         {
 106  0
             return ((HtmlSelectManyListbox)uiComponent).isDisabled();
 107  
         }
 108  0
         else if (uiComponent instanceof HtmlSelectOneListbox)
 109  
         {
 110  0
             return ((HtmlSelectOneListbox)uiComponent).isDisabled();
 111  
         }
 112  
         else
 113  
         {
 114  0
             return org.apache.myfaces.shared.renderkit.RendererUtils.getBooleanAttribute(uiComponent, 
 115  
                     org.apache.myfaces.shared.renderkit.html.HTML.DISABLED_ATTR, false);
 116  
         }
 117  
     }
 118  
 
 119  
 
 120  
     public void decode(FacesContext facesContext, UIComponent uiComponent)
 121  
     {
 122  0
         RendererUtils.checkParamValidity(facesContext, uiComponent, null);
 123  
 
 124  0
         if (uiComponent instanceof UISelectMany)
 125  
         {
 126  0
             HtmlRendererUtils.decodeUISelectMany(facesContext, uiComponent);
 127  
         }
 128  0
         else if (uiComponent instanceof UISelectOne)
 129  
         {
 130  0
             HtmlRendererUtils.decodeUISelectOne(facesContext, uiComponent);
 131  
         }
 132  
         else
 133  
         {
 134  0
             throw new IllegalArgumentException("Unsupported component class " + uiComponent.getClass().getName());
 135  
         }
 136  0
         if (uiComponent instanceof ClientBehaviorHolder &&
 137  
                 !HtmlRendererUtils.isDisabled(uiComponent))
 138  
         {
 139  0
             HtmlRendererUtils.decodeClientBehaviors(facesContext, uiComponent);
 140  
         }
 141  0
     }
 142  
 
 143  
     public Object getConvertedValue(FacesContext facesContext, UIComponent uiComponent, Object submittedValue)
 144  
          throws ConverterException
 145  
     {
 146  0
         org.apache.myfaces.shared.renderkit.RendererUtils.checkParamValidity(facesContext, uiComponent, null);
 147  
 
 148  0
         if (uiComponent instanceof UISelectMany)
 149  
         {
 150  0
             return org.apache.myfaces.shared.renderkit.RendererUtils.getConvertedUISelectManyValue(facesContext,
 151  
                                                                (UISelectMany)uiComponent,
 152  
                                                                submittedValue);
 153  
         }
 154  0
         else if (uiComponent instanceof UISelectOne)
 155  
         {
 156  0
             return RendererUtils.getConvertedUISelectOneValue(facesContext,
 157  
                                                            (UISelectOne)uiComponent,
 158  
                                                            submittedValue);
 159  
         }
 160  
         else
 161  
         {
 162  0
             throw new IllegalArgumentException("Unsupported component class " + uiComponent.getClass().getName());
 163  
         }
 164  
     }
 165  
     
 166  
     /**
 167  
      * Gets the converter for the given component rendered by this renderer.
 168  
      * @param facesContext
 169  
      * @param component
 170  
      * @return
 171  
      */
 172  
     protected Converter getConverter(FacesContext facesContext,
 173  
             UIComponent component)
 174  
     {
 175  0
         if (component instanceof UISelectMany)
 176  
         {
 177  0
             return HtmlRendererUtils.findUISelectManyConverterFailsafe(facesContext, 
 178  
                     (UISelectMany) component);
 179  
         }
 180  0
         else if (component instanceof UISelectOne)
 181  
         {
 182  0
             return HtmlRendererUtils.findUIOutputConverterFailSafe(facesContext, component);
 183  
         }
 184  0
         return null;
 185  
     }
 186  
 
 187  
 }