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