Coverage Report - org.seasar.teeda.core.render.html.HtmlSelectOneListboxRenderer
 
Classes in this File Line Coverage Branch Coverage Complexity
HtmlSelectOneListboxRenderer
96%
22/23
90%
9/10
2.2
 
 1  
 /*
 2  
  * Copyright 2004-2011 the Seasar Foundation and the Others.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 package org.seasar.teeda.core.render.html;
 17  
 
 18  
 import java.io.IOException;
 19  
 import java.util.Map;
 20  
 
 21  
 import javax.faces.component.UIComponent;
 22  
 import javax.faces.component.UIOutput;
 23  
 import javax.faces.component.html.HtmlSelectOneListbox;
 24  
 import javax.faces.context.ExternalContext;
 25  
 import javax.faces.context.FacesContext;
 26  
 import javax.faces.context.ResponseWriter;
 27  
 import javax.faces.convert.ConverterException;
 28  
 import javax.faces.el.ValueBinding;
 29  
 
 30  
 import org.seasar.teeda.core.JsfConstants;
 31  
 import org.seasar.teeda.core.util.PostbackUtil;
 32  
 import org.seasar.teeda.core.util.RendererUtil;
 33  
 import org.seasar.teeda.core.util.ValueHolderUtil;
 34  
 
 35  
 /**
 36  
  * @author manhole
 37  
  */
 38  91
 public class HtmlSelectOneListboxRenderer extends HtmlSelectManyListboxRenderer {
 39  
 
 40  
     public static final String COMPONENT_FAMILY = "javax.faces.SelectOne";
 41  
 
 42  
     public static final String RENDERER_TYPE = "javax.faces.Listbox";
 43  
 
 44  
     protected void renderMultiple(FacesContext context, UIComponent component,
 45  
             ResponseWriter writer) throws IOException {
 46  32
     }
 47  
 
 48  
     protected String[] getValuesForRender(FacesContext context,
 49  
             UIComponent component) {
 50  32
         final ExternalContext externalContext = context.getExternalContext();
 51  32
         final Map requestMap = externalContext.getRequestMap();
 52  32
         final String value = ValueHolderUtil.getValueForRender(context, component);
 53  32
         if (value == null) {
 54  0
             return null;
 55  
         }
 56  32
         if (!PostbackUtil.isPostback(requestMap)) {
 57  28
             final ValueBinding vb = component.getValueBinding("value");
 58  28
             if (vb != null) {
 59  5
                 final Class type = vb.getType(context);
 60  5
                 if (type.isPrimitive() && value.equals("0")) {
 61  2
                     return null;
 62  
                 }
 63  
             }
 64  
         }
 65  30
         return new String[] { value };
 66  
     }
 67  
 
 68  
     public void decode(FacesContext context, UIComponent component) {
 69  8
         assertNotNull(context, component);
 70  4
         getDecoder().decode(context, component);
 71  4
     }
 72  
 
 73  
     public Object getConvertedValue(FacesContext context,
 74  
             UIComponent component, Object submittedValue)
 75  
             throws ConverterException {
 76  5
         assertNotNull(context, component);
 77  1
         return RendererUtil.getConvertedUIOutputValue(context,
 78  
                 (UIOutput) component, submittedValue);
 79  
     }
 80  
 
 81  
     protected void renderStyleClass(FacesContext context,
 82  
             UIComponent component, ResponseWriter writer) throws IOException {
 83  17
         HtmlSelectOneListbox htmlSelectOneListbox = (HtmlSelectOneListbox) component;
 84  17
         final String styleClass = htmlSelectOneListbox.getStyleClass();
 85  17
         RendererUtil.renderAttribute(writer, JsfConstants.STYLE_CLASS_ATTR,
 86  
                 styleClass);
 87  17
     }
 88  
 
 89  
 }