001 package org.apache.myfaces.tobago.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 static org.apache.myfaces.tobago.TobagoConstants.ATTR_TAB_INDEX; 021 022 import javax.faces.application.Application; 023 import javax.faces.context.FacesContext; 024 import javax.faces.convert.Converter; 025 import javax.faces.convert.DateTimeConverter; 026 import static javax.faces.convert.DateTimeConverter.CONVERTER_ID; 027 import javax.faces.el.ValueBinding; 028 import java.util.TimeZone; 029 030 /* 031 * Date: 10.02.2006 032 * Time: 20:50:49 033 */ 034 public class UITimeInput extends javax.faces.component.UIInput { 035 036 public static final String COMPONENT_TYPE = "org.apache.myfaces.tobago.TimeInput"; 037 038 private Integer tabIndex; 039 040 public Converter getConverter() { 041 Converter converter = super.getConverter(); 042 if (converter == null) { 043 // setting required default converter 044 Application application 045 = FacesContext.getCurrentInstance().getApplication(); 046 DateTimeConverter dateTimeConverter 047 = (DateTimeConverter) application.createConverter(CONVERTER_ID); 048 dateTimeConverter.setPattern("HH:mm"); 049 dateTimeConverter.setTimeZone(TimeZone.getDefault()); 050 setConverter(dateTimeConverter); 051 } 052 return converter; 053 } 054 055 public void restoreState(FacesContext context, Object state) { 056 Object[] values = (Object[]) state; 057 super.restoreState(context, values[0]); 058 tabIndex = (Integer) values[1]; 059 } 060 061 public Object saveState(FacesContext context) { 062 Object[] values = new Object[2]; 063 values[0] = super.saveState(context); 064 values[1] = tabIndex; 065 return values; 066 } 067 068 public Integer getTabIndex() { 069 if (tabIndex != null) { 070 return tabIndex; 071 } 072 ValueBinding vb = getValueBinding(ATTR_TAB_INDEX); 073 if (vb != null) { 074 Number number = (Number) vb.getValue(getFacesContext()); 075 if (number != null) { 076 return Integer.valueOf(number.intValue()); 077 } 078 } 079 return null; 080 } 081 082 public void setTabIndex(Integer tabIndex) { 083 this.tabIndex = tabIndex; 084 } 085 }