001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019 020 package org.apache.myfaces.tobago.component; 021 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 027 /* 028 * Date: Feb 17, 2007 029 * Time: 8:53:17 AM 030 */ 031 public class UIButtonCommand extends UICommand implements SupportsMarkup { 032 033 public static final String COMPONENT_TYPE = "org.apache.myfaces.tobago.ButtonCommand"; 034 035 private String[] markup; 036 private Integer tabIndex; 037 038 public void restoreState(FacesContext context, Object state) { 039 Object[] values = (Object[]) state; 040 super.restoreState(context, values[0]); 041 042 markup = (String[]) values[1]; 043 tabIndex = (Integer) values[2]; 044 } 045 046 public Object saveState(FacesContext context) { 047 Object[] values = new Object[3]; 048 values[0] = super.saveState(context); 049 values[1] = markup; 050 values[2] = tabIndex; 051 return values; 052 } 053 054 public String[] getMarkup() { 055 if (markup != null) { 056 return markup; 057 } 058 return ComponentUtil.getMarkupBinding(getFacesContext(), this); 059 } 060 061 public void setMarkup(String[] markup) { 062 this.markup = markup; 063 } 064 065 public Integer getTabIndex() { 066 if (tabIndex != null) { 067 return tabIndex; 068 } 069 ValueBinding vb = getValueBinding(ATTR_TAB_INDEX); 070 if (vb != null) { 071 Number number = (Number) vb.getValue(getFacesContext()); 072 if (number != null) { 073 return Integer.valueOf(number.intValue()); 074 } 075 } 076 return null; 077 } 078 079 public void setTabIndex(Integer tabIndex) { 080 this.tabIndex = tabIndex; 081 } 082 083 }