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 org.apache.commons.logging.Log; 021 import org.apache.commons.logging.LogFactory; 022 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_TAB_INDEX; 023 024 import javax.faces.context.FacesContext; 025 import javax.faces.el.ValueBinding; 026 import java.io.IOException; 027 028 /* 029 * User: weber 030 * Date: May 31, 2005 031 * Time: 7:47:11 PM 032 */ 033 public class UISelectMany extends javax.faces.component.UISelectMany implements SupportsMarkup { 034 035 private static final Log LOG = LogFactory.getLog(UISelectMany.class); 036 037 public static final String COMPONENT_TYPE = "org.apache.myfaces.tobago.SelectMany"; 038 039 private String[] markup; 040 private Integer tabIndex; 041 042 public void restoreState(FacesContext context, Object state) { 043 Object[] values = (Object[]) state; 044 super.restoreState(context, values[0]); 045 markup = (String[]) values[1]; 046 tabIndex = (Integer) values[2]; 047 } 048 049 public Object saveState(FacesContext context) { 050 Object[] values = new Object[3]; 051 values[0] = super.saveState(context); 052 values[1] = markup; 053 values[2] = tabIndex; 054 return values; 055 } 056 057 public String[] getMarkup() { 058 if (markup != null) { 059 return markup; 060 } 061 return ComponentUtil.getMarkupBinding(getFacesContext(), this); 062 } 063 064 public void setMarkup(String[] markup) { 065 this.markup = markup; 066 } 067 068 069 public void encodeBegin(FacesContext facesContext) throws IOException { 070 // TODO change this should be renamed to DimensionUtils.prepare!!! 071 UILayout.getLayout(this).layoutBegin(facesContext, this); 072 super.encodeBegin(facesContext); 073 } 074 075 public Integer getTabIndex() { 076 if (tabIndex != null) { 077 return tabIndex; 078 } 079 ValueBinding vb = getValueBinding(ATTR_TAB_INDEX); 080 if (vb != null) { 081 Number number = (Number) vb.getValue(getFacesContext()); 082 if (number != null) { 083 return Integer.valueOf(number.intValue()); 084 } 085 } 086 return null; 087 } 088 089 public void setTabIndex(Integer tabIndex) { 090 this.tabIndex = tabIndex; 091 } 092 093 }