001    package org.apache.myfaces.tobago.taglib.component;
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 org.apache.commons.logging.Log;
021    import org.apache.commons.logging.LogFactory;
022    import static org.apache.myfaces.tobago.TobagoConstants.ATTR_FOCUS;
023    import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ONCHANGE;
024    import static org.apache.myfaces.tobago.TobagoConstants.ATTR_TAB_INDEX;
025    import static org.apache.myfaces.tobago.TobagoConstants.ATTR_TIP;
026    import org.apache.myfaces.tobago.component.ComponentUtil;
027    
028    import javax.faces.component.EditableValueHolder;
029    import javax.faces.component.UIComponent;
030    
031    public abstract class InputTag extends BeanTag implements InputTagDeclaration {
032      private static final Log LOG = LogFactory.getLog(InputTag.class);
033    
034      private String onchange;
035      private String focus;
036      private String tip;
037      private String validator;
038      private String valueChangeListener;
039      private String tabIndex;
040    
041      public void release() {
042        super.release();
043        this.onchange = null;
044        this.focus = null;
045        tip = null;
046        validator = null;
047        valueChangeListener = null;
048        tabIndex = null;
049      }
050    
051      protected void setProperties(UIComponent component) {
052        super.setProperties(component);
053        ComponentUtil.setStringProperty(component, ATTR_ONCHANGE, onchange);
054        ComponentUtil.setBooleanProperty(component, ATTR_FOCUS, focus);
055        ComponentUtil.setStringProperty(component, ATTR_TIP, tip);
056        ComponentUtil.setIntegerProperty(component, ATTR_TAB_INDEX, tabIndex);
057        if (component instanceof EditableValueHolder) {
058          EditableValueHolder editableValueHolder = (EditableValueHolder) component;
059          ComponentUtil.setValidator(editableValueHolder, validator);
060          ComponentUtil.setValueChangeListener(editableValueHolder, valueChangeListener);
061        }
062      }
063    
064      public String getOnchange() {
065        return onchange;
066      }
067    
068      public void setOnchange(String onchange) {
069        this.onchange = onchange;
070      }
071    
072      public String getFocus() {
073        return focus;
074      }
075    
076      public void setFocus(String focus) {
077        this.focus = focus;
078      }
079    
080      public String getAccessKey() {
081        return null;
082      }
083    
084      public void setAccessKey(String accessKey) {
085        LOG.warn("Attibute 'accessKey' is deprecated, "
086            + "and will removed soon!");
087      }
088    
089      public String getLabelWithAccessKey() {
090        return null;
091      }
092    
093      public void setLabelWithAccessKey(String labelWithAccessKey) {
094        LOG.warn("Attibute 'labelWithAccessKey' is deprecated, "
095            + "and will removed soon! Please use 'label' instead.");
096        setLabel(labelWithAccessKey);
097      }
098    
099      public String getTip() {
100        return tip;
101      }
102    
103      public void setTip(String tip) {
104        this.tip = tip;
105      }
106    
107      public String getValidator() {
108        return validator;
109      }
110    
111      public void setValidator(String validator) {
112        this.validator = validator;
113      }
114    
115      public String getValueChangeListener() {
116        return valueChangeListener;
117      }
118    
119      public void setValueChangeListener(String valueChangeListener) {
120        this.valueChangeListener = valueChangeListener;
121      }
122    
123      public String getTabIndex() {
124        return tabIndex;
125      }
126    
127      public void setTabIndex(String tabIndex) {
128        this.tabIndex = tabIndex;
129      }
130    }
131