Coverage Report - org.seasar.teeda.core.render.html.HtmlSelectOneRadioRenderer
 
Classes in this File Line Coverage Branch Coverage Complexity
HtmlSelectOneRadioRenderer
100%
36/36
100%
4/4
1.4
 
 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  
 
 20  
 import javax.faces.component.UIComponent;
 21  
 import javax.faces.component.UIOutput;
 22  
 import javax.faces.context.FacesContext;
 23  
 import javax.faces.context.ResponseWriter;
 24  
 import javax.faces.convert.ConverterException;
 25  
 import javax.faces.internal.IgnoreAttribute;
 26  
 import javax.faces.model.SelectItem;
 27  
 
 28  
 import org.seasar.teeda.core.JsfConstants;
 29  
 import org.seasar.teeda.core.util.RendererUtil;
 30  
 import org.seasar.teeda.core.util.ValueHolderUtil;
 31  
 
 32  
 /**
 33  
  * @author manhole
 34  
  * @author shot
 35  
  */
 36  43
 public class HtmlSelectOneRadioRenderer extends HtmlSelectManyCheckboxRenderer {
 37  
 
 38  
     public static final String COMPONENT_FAMILY = "javax.faces.SelectOne";
 39  
 
 40  
     public static final String RENDERER_TYPE = "javax.faces.Radio";
 41  
 
 42  43
     private final IgnoreAttribute ignoreComponent = new IgnoreAttribute();
 43  
     {
 44  43
         ignoreComponent.addAttributeName(JsfConstants.ID_ATTR);
 45  43
         ignoreComponent.addAttributeName(JsfConstants.VALUE_ATTR);
 46  43
         ignoreComponent.addAttributeName(JsfConstants.LAYOUT_ATTR);
 47  43
         ignoreComponent.addAttributeName(JsfConstants.DISABLED_ATTR);
 48  43
         ignoreComponent.addAttributeName(JsfConstants.DISABLED_CLASS_ATTR);
 49  43
         ignoreComponent.addAttributeName(JsfConstants.ENABLED_CLASS_ATTR);
 50  43
         ignoreComponent.addAttributeName(JsfConstants.BORDER_ATTR);
 51  43
         ignoreComponent.addAttributeName(JsfConstants.STYLE_ATTR);
 52  43
         ignoreComponent.addAttributeName(JsfConstants.STYLE_CLASS_ATTR);
 53  43
         ignoreComponent.addAttributeName(JsfConstants.NAME_ATTR);
 54  43
         ignoreComponent.addAttributeName(JsfConstants.TYPE_ATTR);
 55  43
         ignoreComponent.addAttributeName(JsfConstants.CHECKED_ATTR);
 56  43
     }
 57  
 
 58  
     protected void renderInputElement(FacesContext context,
 59  
             UIComponent htmlSelectManyCheckbox, ResponseWriter writer,
 60  
             String[] selectedValues, final SelectItem selectItem,
 61  
             final boolean disabled) throws IOException {
 62  
 
 63  21
         writer.startElement(JsfConstants.INPUT_ELEM, htmlSelectManyCheckbox);
 64  21
         RendererUtil.renderAttribute(writer, JsfConstants.TYPE_ATTR,
 65  
                 JsfConstants.RADIO_VALUE);
 66  21
         RendererUtil.renderAttribute(writer, JsfConstants.NAME_ATTR,
 67  
                 htmlSelectManyCheckbox.getClientId(context));
 68  21
         final Object value = selectItem.getValue();
 69  21
         RendererUtil.renderAttribute(writer, JsfConstants.VALUE_ATTR, value);
 70  21
         renderRemainAttributes(htmlSelectManyCheckbox, writer, ignoreComponent);
 71  21
         if (isChecked(selectedValues, value.toString())) {
 72  2
             renderCheckedAttribute(writer);
 73  
         }
 74  21
         if (disabled) {
 75  7
             renderDisabledAttribute(writer);
 76  
         }
 77  21
         writer.endElement(JsfConstants.INPUT_ELEM);
 78  21
     }
 79  
 
 80  
     protected String[] getValuesForRender(FacesContext context,
 81  
             UIComponent component) {
 82  13
         String value = ValueHolderUtil.getValueForRender(context, component);
 83  
         // value is not null
 84  13
         return new String[] { value };
 85  
     }
 86  
 
 87  
     public void decode(FacesContext context, UIComponent component) {
 88  4
         assertNotNull(context, component);
 89  2
         getDecoder().decode(context, component);
 90  2
     }
 91  
 
 92  
     public Object getConvertedValue(FacesContext context,
 93  
             UIComponent component, Object submittedValue)
 94  
             throws ConverterException {
 95  3
         assertNotNull(context, component);
 96  1
         return RendererUtil.getConvertedUIOutputValue(context,
 97  
                 (UIOutput) component, submittedValue);
 98  
     }
 99  
 
 100  
     public void addIgnoreAttributeName(final String name) {
 101  31
         ignoreComponent.addAttributeName(name);
 102  31
     }
 103  
 
 104  
 }