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