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