Coverage Report - org.apache.myfaces.shared_impl.renderkit.html.HtmlListboxRendererBase
 
Classes in this File Line Coverage Branch Coverage Complexity
HtmlListboxRendererBase
0%
0/27
0%
0/16
4.75
 
 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_impl.renderkit.html;
 20  
 
 21  
 import org.apache.myfaces.shared_impl.renderkit.JSFAttr;
 22  
 import org.apache.myfaces.shared_impl.renderkit.RendererUtils;
 23  
 
 24  
 import javax.faces.component.UIComponent;
 25  
 import javax.faces.component.UISelectMany;
 26  
 import javax.faces.component.UISelectOne;
 27  
 import javax.faces.component.html.HtmlSelectManyListbox;
 28  
 import javax.faces.component.html.HtmlSelectOneListbox;
 29  
 import javax.faces.context.FacesContext;
 30  
 import javax.faces.convert.ConverterException;
 31  
 import java.io.IOException;
 32  
 
 33  
 
 34  
 /**
 35  
  * @author Thomas Spiegl (latest modification by $Author: matzew $)
 36  
  * @author Anton Koinov
 37  
  * @version $Revision: 597729 $ $Date: 2007-11-23 14:25:55 -0500 (Fri, 23 Nov 2007) $
 38  
  */
 39  0
 public class HtmlListboxRendererBase
 40  
         extends HtmlRenderer
 41  
 {
 42  
     public void encodeEnd(FacesContext facesContext, UIComponent uiComponent)
 43  
             throws IOException
 44  
     {
 45  0
         org.apache.myfaces.shared_impl.renderkit.RendererUtils.checkParamValidity(facesContext, uiComponent, null);
 46  
 
 47  0
         int size = (Integer)uiComponent.getAttributes().get(JSFAttr.SIZE_ATTR);
 48  
 
 49  0
         if (uiComponent instanceof UISelectMany)
 50  
         {
 51  0
             HtmlRendererUtils.renderListbox(facesContext,
 52  
                                             (UISelectMany)uiComponent,
 53  
                                             isDisabled(facesContext, uiComponent),
 54  
                                             size);
 55  
         }
 56  0
         else if (uiComponent instanceof HtmlSelectOneListbox)
 57  
         {
 58  0
             HtmlRendererUtils.renderListbox(facesContext,
 59  
                                             (UISelectOne)uiComponent,
 60  
                                             isDisabled(facesContext, uiComponent),
 61  
                                             size);
 62  
         }
 63  
         else
 64  
         {
 65  0
             throw new IllegalArgumentException("Unsupported component class " + uiComponent.getClass().getName());
 66  
         }
 67  0
     }
 68  
 
 69  
     protected boolean isDisabled(FacesContext facesContext, UIComponent uiComponent)
 70  
     {
 71  
         //TODO: overwrite in extended HtmlListboxRenderer and check for enabledOnUserRole
 72  0
         if (uiComponent instanceof HtmlSelectManyListbox)
 73  
         {
 74  0
             return ((HtmlSelectManyListbox)uiComponent).isDisabled();
 75  
         }
 76  0
         else if (uiComponent instanceof HtmlSelectOneListbox)
 77  
         {
 78  0
             return ((HtmlSelectOneListbox)uiComponent).isDisabled();
 79  
         }
 80  
         else
 81  
         {
 82  0
             return org.apache.myfaces.shared_impl.renderkit.RendererUtils.getBooleanAttribute(uiComponent, org.apache.myfaces.shared_impl.renderkit.html.HTML.DISABLED_ATTR, false);
 83  
         }
 84  
     }
 85  
 
 86  
 
 87  
     public void decode(FacesContext facesContext, UIComponent uiComponent)
 88  
     {
 89  0
         RendererUtils.checkParamValidity(facesContext, uiComponent, null);
 90  
 
 91  0
         if (uiComponent instanceof UISelectMany)
 92  
         {
 93  0
             HtmlRendererUtils.decodeUISelectMany(facesContext, uiComponent);
 94  
         }
 95  0
         else if (uiComponent instanceof UISelectOne)
 96  
         {
 97  0
             HtmlRendererUtils.decodeUISelectOne(facesContext, uiComponent);
 98  
         }
 99  
         else
 100  
         {
 101  0
             throw new IllegalArgumentException("Unsupported component class " + uiComponent.getClass().getName());
 102  
         }
 103  0
     }
 104  
 
 105  
     public Object getConvertedValue(FacesContext facesContext, UIComponent uiComponent, Object submittedValue) throws ConverterException
 106  
     {
 107  0
         org.apache.myfaces.shared_impl.renderkit.RendererUtils.checkParamValidity(facesContext, uiComponent, null);
 108  
 
 109  0
         if (uiComponent instanceof UISelectMany)
 110  
         {
 111  0
             return org.apache.myfaces.shared_impl.renderkit.RendererUtils.getConvertedUISelectManyValue(facesContext,
 112  
                                                                (UISelectMany)uiComponent,
 113  
                                                                submittedValue);
 114  
         }
 115  0
         else if (uiComponent instanceof UISelectOne)
 116  
         {
 117  0
             return RendererUtils.getConvertedUISelectOneValue(facesContext,
 118  
                                                            (UISelectOne)uiComponent,
 119  
                                                            submittedValue);
 120  
         }
 121  
         else
 122  
         {
 123  0
             throw new IllegalArgumentException("Unsupported component class " + uiComponent.getClass().getName());
 124  
         }
 125  
     }
 126  
 
 127  
 }