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_IMMEDIATE; 023 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SHOW_NAVIGATION_BAR; 024 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SELECTED_INDEX; 025 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SWITCH_TYPE; 026 import org.apache.myfaces.tobago.component.ComponentUtil; 027 import org.apache.myfaces.tobago.component.UITabGroup; 028 import static org.apache.myfaces.tobago.component.UITabGroup.SWITCH_TYPE_CLIENT; 029 import static org.apache.myfaces.tobago.component.UITabGroup.SWITCH_TYPE_RELOAD_PAGE; 030 031 import javax.faces.component.UIComponent; 032 import javax.faces.context.FacesContext; 033 import javax.faces.application.Application; 034 035 public class TabGroupTag extends TobagoTag 036 implements TabGroupTagDeclaration { 037 038 private static final Log LOG = LogFactory.getLog(TabGroupTag.class); 039 040 private String selectedIndex; 041 private String switchType; 042 private String immediate; 043 private String state; 044 private String showNavigationBar; 045 private String tabChangeListener; 046 047 @Override 048 public String getComponentType() { 049 return UITabGroup.COMPONENT_TYPE; 050 } 051 052 @Override 053 protected void setProperties(UIComponent component) { 054 super.setProperties(component); 055 ComponentUtil.setIntegerProperty(component, ATTR_SELECTED_INDEX, selectedIndex); 056 ComponentUtil.setIntegerProperty(component, ATTR_SELECTED_INDEX, state); 057 ComponentUtil.setStringProperty(component, ATTR_SWITCH_TYPE, switchType); 058 ComponentUtil.setBooleanProperty(component, ATTR_IMMEDIATE, immediate); 059 ComponentUtil.setBooleanProperty(component, ATTR_SHOW_NAVIGATION_BAR, showNavigationBar); 060 if (tabChangeListener != null && component instanceof UITabGroup && isValueReference(tabChangeListener)) { 061 final Application application = FacesContext.getCurrentInstance().getApplication(); 062 final javax.faces.el.MethodBinding methodBinding = application.createMethodBinding(tabChangeListener, 063 new Class[] {org.apache.myfaces.tobago.event.TabChangeEvent.class}); 064 ((UITabGroup) component).setTabChangeListener(methodBinding); 065 } 066 } 067 068 @Override 069 public void release() { 070 super.release(); 071 state = null; 072 switchType = null; 073 immediate = null; 074 selectedIndex = null; 075 showNavigationBar = null; 076 tabChangeListener = null; 077 } 078 079 public void setServerside(String serverside) { 080 LOG.warn("Attribute 'serverside' is deprecated! Use 'switchType' instead."); 081 this.switchType = Boolean.valueOf(serverside) 082 ? SWITCH_TYPE_RELOAD_PAGE : SWITCH_TYPE_CLIENT; 083 } 084 085 public void setState(String state) { 086 this.state = state; 087 } 088 089 public void setSelectedIndex(String selectedIndex) { 090 this.selectedIndex = selectedIndex; 091 } 092 093 public void setSwitchType(String switchType) { 094 this.switchType = switchType; 095 } 096 097 public void setImmediate(String immediate) { 098 this.immediate = immediate; 099 } 100 101 public String getShowNavigationBar() { 102 return showNavigationBar; 103 } 104 105 public void setShowNavigationBar(String showNavigationBar) { 106 this.showNavigationBar = showNavigationBar; 107 } 108 109 public String getTabChangeListener() { 110 return tabChangeListener; 111 } 112 113 public void setTabChangeListener(final String tabChangeListener) { 114 this.tabChangeListener = tabChangeListener; 115 } 116 } 117