001    package org.apache.myfaces.tobago.facelets.extension;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one or more
005     * contributor license agreements.  See the NOTICE file distributed with
006     * this work for additional information regarding copyright ownership.
007     * The ASF licenses this file to You under the Apache License, Version 2.0
008     * (the "License"); you may not use this file except in compliance with
009     * the License.  You may obtain a copy of the License at
010     *
011     *      http://www.apache.org/licenses/LICENSE-2.0
012     *
013     * Unless required by applicable law or agreed to in writing, software
014     * distributed under the License is distributed on an "AS IS" BASIS,
015     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016     * See the License for the specific language governing permissions and
017     * limitations under the License.
018     */
019    
020    import com.sun.facelets.FaceletContext;
021    import com.sun.facelets.el.ELAdaptor;
022    import com.sun.facelets.tag.TagAttribute;
023    import com.sun.facelets.tag.jsf.ComponentConfig;
024    import org.apache.myfaces.tobago.component.Attributes;
025    import org.apache.myfaces.tobago.component.RendererTypes;
026    import org.apache.myfaces.tobago.component.UISelectBooleanCheckbox;
027    
028    import javax.el.ValueExpression;
029    import javax.faces.component.UIComponent;
030    
031    public class SelectBooleanCheckboxExtensionHandler extends TobagoLabelExtensionHandler {
032    
033      private TagAttribute itemLabelAttribute;
034    
035      public SelectBooleanCheckboxExtensionHandler(ComponentConfig config) {
036        super(config);
037        itemLabelAttribute = getAttribute(Attributes.ITEM_LABEL);
038      }
039    
040      protected void enrichInput(FaceletContext faceletContext, UIComponent input) {
041        super.enrichInput(faceletContext, input);
042        UISelectBooleanCheckbox checkbox = (UISelectBooleanCheckbox) input;
043        if (itemLabelAttribute != null) {
044          if (itemLabelAttribute.isLiteral()) {
045            checkbox.setLabel(itemLabelAttribute.getValue(faceletContext));
046          } else {
047            ValueExpression expression = itemLabelAttribute.getValueExpression(faceletContext, String.class);
048            ELAdaptor.setExpression(checkbox, Attributes.TIP, expression);
049          }
050        }
051      }
052    
053      protected String getSubComponentType() {
054        return UISelectBooleanCheckbox.COMPONENT_TYPE;
055      }
056    
057      protected String getSubRendererType() {
058        return RendererTypes.SELECT_BOOLEAN_CHECKBOX;
059      }
060    }