You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by bo...@apache.org on 2007/01/06 11:03:38 UTC

svn commit: r493439 - in /myfaces/tobago/trunk: core/src/main/java/org/apache/myfaces/tobago/component/ core/src/main/java/org/apache/myfaces/tobago/context/ core/src/main/java/org/apache/myfaces/tobago/taglib/component/ theme/scarborough/src/main/java...

Author: bommel
Date: Sat Jan  6 02:03:37 2007
New Revision: 493439

URL: http://svn.apache.org/viewvc?view=rev&rev=493439
Log:
(TOBAGO-231) Problem with input validation and tab group
(TOBAGO-232) TabGroup has problems if the tabs have a value bindung for rendered
(TOBAGO-233) TabGroup should support immediate for switching to an other tab

Modified:
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UITabGroup.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerUtil.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/TabGroupTag.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/TabGroupTagDeclaration.java
    myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.java
    myfaces/tobago/trunk/theme/scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/script/tab.js
    myfaces/tobago/trunk/theme/speyside/src/main/java/org/apache/myfaces/tobago/renderkit/html/speyside/standard/tag/TabGroupRenderer.java
    myfaces/tobago/trunk/tobago-tool/gendoc/src/main/webapp/navigation.jsp
    myfaces/tobago/trunk/tobago-tool/gendoc/src/main/webapp/screenshot/tabGroup.jsp

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UITabGroup.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UITabGroup.java?view=diff&rev=493439&r1=493438&r2=493439
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UITabGroup.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UITabGroup.java Sat Jan  6 02:03:37 2007
@@ -19,6 +19,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_IMMEDIATE;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_LAYOUT_HEIGHT;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_LAYOUT_WIDTH;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_STATE;
@@ -27,6 +28,7 @@
 import org.apache.myfaces.tobago.ajax.api.AjaxUtils;
 import org.apache.myfaces.tobago.event.TabChangeListener;
 import org.apache.myfaces.tobago.event.TabChangeSource;
+import org.apache.myfaces.tobago.event.TabChangeEvent;
 
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
@@ -35,6 +37,7 @@
 import javax.faces.el.ValueBinding;
 import javax.faces.event.AbortProcessingException;
 import javax.faces.event.FacesEvent;
+import javax.faces.event.PhaseId;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
@@ -45,15 +48,12 @@
 
   public static final String COMPONENT_TYPE = "org.apache.myfaces.tobago.TabGroup";
 
-  public static final String RENDERED_INDEX
-      = "org.apache.myfaces.tobago.component.UITabGroup.RENDERED_INDEX";
-
   private int activeIndex;
   private int renderedIndex;
-
   private String switchType;
-
+  private Boolean immediate;
   private MethodBinding tabChangeListener = null;
+
   public static final String SWITCH_TYPE_CLIENT = "client";
   public static final String SWITCH_TYPE_RELOAD_PAGE = "reloadPage";
   public static final String SWITCH_TYPE_RELOAD_TAB = "reloadTab";
@@ -79,10 +79,34 @@
     super.encodeBegin(facesContext);
   }
 
+  public void setImmediate(boolean immediate) {
+    this.immediate = immediate;
+  }
+
+   public boolean isImmediate() {
+    if (immediate != null) {
+      return immediate;
+    }
+    ValueBinding vb = getValueBinding(ATTR_IMMEDIATE);
+    if (vb != null) {
+      return (!Boolean.FALSE.equals(vb.getValue(getFacesContext())));
+    } else {
+      return false;
+    }
+  }
+
+  public void queueEvent(FacesEvent event) {
+    if (isImmediate()) {
+      event.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
+    } else {
+      event.setPhaseId(PhaseId.INVOKE_APPLICATION);
+    }
+    super.queueEvent(event);
+  }
+
   @Override
   public void encodeChildren(FacesContext context)
       throws IOException {
-    // childeren are rendered by encodeEnd'jsp
   }
 
   @Override
@@ -91,12 +115,10 @@
     super.encodeEnd(facesContext);
   }
 
-
-
   private void resetTabLayout() {
-    for (UIPanel tab : getTabs()) {
-        tab.getAttributes().remove(ATTR_LAYOUT_WIDTH);
-        tab.getAttributes().remove(ATTR_LAYOUT_HEIGHT);
+    for (UIComponent component : (List<UIComponent>)getChildren()) {
+      component.getAttributes().remove(ATTR_LAYOUT_WIDTH);
+      component.getAttributes().remove(ATTR_LAYOUT_HEIGHT);
     }
   }
 
@@ -105,9 +127,9 @@
     for (Object o : getChildren()) {
       UIComponent kid = (UIComponent) o;
       if (kid instanceof UIPanel) {
-        if (kid.isRendered()) {
+        //if (kid.isRendered()) {
           tabs.add((UIPanel) kid);
-        }
+        //}
       } else {
         LOG.error("Invalid component in UITabGroup: " + kid);
       }
@@ -116,9 +138,10 @@
   }
 
   public UIPanel getActiveTab() {
-    return getTabs()[activeIndex];
+    return getTab(getActiveIndex());
   }
 
+
   @Override
   public void processDecodes(FacesContext context) {
     if (!isClientType()) {
@@ -129,7 +152,7 @@
       if (!isRendered()) {
         return;
       }
-      UIPanel renderedTab = getTabs()[getRenderedIndex()];
+      UIPanel renderedTab = getRenderedTab();
       renderedTab.processDecodes(context);
       try {
         decode(context);
@@ -151,7 +174,7 @@
       if (!isRendered()) {
         return;
       }
-      UIPanel renderedTab = getTabs()[getRenderedIndex()];
+      UIPanel renderedTab = getRenderedTab();
       renderedTab.processValidators(context);
     } else {
       super.processValidators(context);
@@ -167,7 +190,7 @@
       if (!isRendered()) {
         return;
       }
-      UIPanel renderedTab = getTabs()[getRenderedIndex()];
+      UIPanel renderedTab = getRenderedTab();
       renderedTab.processUpdates(context);
       updateState(context);
     } else {
@@ -178,17 +201,19 @@
 
   public void broadcast(FacesEvent facesEvent) throws AbortProcessingException {
     super.broadcast(facesEvent);
-
-    MethodBinding tabChangeListenerBinding = getTabChangeListener();
-    if (tabChangeListenerBinding != null) {
-      try {
-        tabChangeListenerBinding.invoke(getFacesContext(), new Object[]{facesEvent});
-      } catch (EvaluationException e) {
-        Throwable cause = e.getCause();
-        if (cause != null && cause instanceof AbortProcessingException) {
-          throw (AbortProcessingException) cause;
-        } else {
-          throw e;
+    if (facesEvent instanceof TabChangeEvent) {
+      setActiveIndex(((TabChangeEvent)facesEvent).getNewTabIndex());
+      MethodBinding tabChangeListenerBinding = getTabChangeListener();
+      if (tabChangeListenerBinding != null) {
+        try {
+          tabChangeListenerBinding.invoke(getFacesContext(), new Object[]{facesEvent});
+        } catch (EvaluationException e) {
+          Throwable cause = e.getCause();
+          if (cause != null && cause instanceof AbortProcessingException) {
+            throw (AbortProcessingException) cause;
+          } else {
+            throw e;
+          }
         }
       }
     }
@@ -229,12 +254,13 @@
   }
 
   public Object saveState(FacesContext context) {
-    Object[] state = new Object[5];
+    Object[] state = new Object[6];
     state[0] = super.saveState(context);
     state[1] = renderedIndex;
     state[2] = activeIndex;
     state[3] = saveAttachedState(context, tabChangeListener);
     state[4] = switchType;
+    state[5] = immediate;
     return state;
   }
 
@@ -245,10 +271,11 @@
     activeIndex = (Integer) values[2];
     tabChangeListener = (MethodBinding) restoreAttachedState(context, values[3]);
     switchType = (String) values[4];
+    immediate = (Boolean) values[5];
   }
 
   public void encodeAjax(FacesContext facesContext) throws IOException {
-    if (activeIndex < 0 || !(activeIndex < getTabs().length)) {
+    if (activeIndex < 0 || !(activeIndex < getChildCount())) {
       LOG.error("This should never occur! Problem in decoding?");
       ValueBinding stateBinding = getValueBinding(ATTR_STATE);
       Object state
@@ -307,5 +334,25 @@
 
   public void setSwitchType(String switchType) {
     this.switchType = switchType;
+  }
+
+  private UIPanel getTab(int index) {
+    int i = 0;
+    for (UIComponent component : (List<UIComponent>)getChildren()) {
+      if (component instanceof UIPanel) {
+        if (i == index) {
+          return (UIPanel) component;
+        }
+        i++;
+      } else {
+        LOG.error("Invalid component in UITabGroup: " + component);
+      }
+    }
+    System.err.println("Found no component with "+ index + " " + getChildCount());
+    return null;
+  }
+
+  private UIPanel getRenderedTab() {
+    return getTab(getRenderedIndex());
   }
 }

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerUtil.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerUtil.java?view=diff&rev=493439&r1=493438&r2=493439
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerUtil.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerUtil.java Sat Jan  6 02:03:37 2007
@@ -72,8 +72,9 @@
   public static List<String> getStyles(FacesContext facesContext, String name) {
     UIViewRoot viewRoot = facesContext.getViewRoot();
     String contextPath = facesContext.getExternalContext().getRequestContextPath();
-    String[] styles = ResourceManagerFactory.getResourceManager(facesContext).getStyles(viewRoot, name);
 
+    String[] styles = ResourceManagerFactory.getResourceManager(facesContext).getStyles(viewRoot, name);
+    System.err.println(styles);
     return addContextPath(styles, contextPath);
   }
 

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/TabGroupTag.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/TabGroupTag.java?view=diff&rev=493439&r1=493438&r2=493439
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/TabGroupTag.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/TabGroupTag.java Sat Jan  6 02:03:37 2007
@@ -19,6 +19,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_IMMEDIATE;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_STATE;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SWITCH_TYPE;
 import org.apache.myfaces.tobago.component.ComponentUtil;
@@ -35,6 +36,7 @@
 
   private String state;
   private String switchType;
+  private String immediate;
 
   @Override
   public String getComponentType() {
@@ -46,12 +48,15 @@
     super.setProperties(component);
     ComponentUtil.setValueBinding(component, ATTR_STATE, state);
     ComponentUtil.setStringProperty(component, ATTR_SWITCH_TYPE, switchType);
+    ComponentUtil.setBooleanProperty(component, ATTR_IMMEDIATE, immediate);
   }
 
   @Override
   public void release() {
     super.release();
     state = null;
+    switchType = null;
+    immediate = null;
   }
 
   public void setServerside(String serverside) {
@@ -66,6 +71,10 @@
 
   public void setSwitchType(String switchType) {
     this.switchType = switchType;
+  }
+  
+  public void setImmediate(String immediate) {
+    this.immediate = immediate;
   }
 }
 

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/TabGroupTagDeclaration.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/TabGroupTagDeclaration.java?view=diff&rev=493439&r1=493438&r2=493439
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/TabGroupTagDeclaration.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/TabGroupTagDeclaration.java Sat Jan  6 02:03:37 2007
@@ -26,6 +26,7 @@
 import org.apache.myfaces.tobago.taglib.decl.HasDeprecatedDimension;
 import org.apache.myfaces.tobago.taglib.decl.HasIdBindingAndRendered;
 import org.apache.myfaces.tobago.taglib.decl.HasState;
+import org.apache.myfaces.tobago.taglib.decl.IsImmediateCommand;
 
 /*
  * Created by IntelliJ IDEA.
@@ -44,7 +45,7 @@
     rendererType = "TabGroup")
 
 public interface TabGroupTagDeclaration extends TobagoTagDeclaration, HasIdBindingAndRendered, HasDeprecatedDimension,
-    HasState {
+    HasState, IsImmediateCommand {
   /**
    * Deprecated! Use 'switchType' instead.
    * Flag indicating that tab switching is done by server request.
@@ -64,6 +65,9 @@
    *   "reloadTab"  : Tab switching id done by server request. Only the Tab is reloaded.
    */
   @TagAttribute
-  @UIComponentTagAttribute(type = "java.lang.String", defaultValue = UITabGroup.SWITCH_TYPE_CLIENT)
+  @UIComponentTagAttribute(type = "java.lang.String",
+      allowedValues =
+          {UITabGroup.SWITCH_TYPE_CLIENT, UITabGroup.SWITCH_TYPE_RELOAD_PAGE, UITabGroup.SWITCH_TYPE_RELOAD_TAB},
+      defaultValue = UITabGroup.SWITCH_TYPE_CLIENT)
   void setSwitchType(String switchType);
 }

Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.java?view=diff&rev=493439&r1=493438&r2=493439
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.java Sat Jan  6 02:03:37 2007
@@ -54,16 +54,11 @@
 import org.apache.myfaces.tobago.util.AccessKeyMap;
 import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
 
-import javax.faces.component.UICommand;
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
-import javax.faces.el.EvaluationException;
-import javax.faces.el.MethodBinding;
-import javax.faces.el.MethodNotFoundException;
-import javax.faces.event.ActionEvent;
-import javax.faces.event.PhaseId;
 import java.io.IOException;
 import java.util.Map;
+import java.util.List;
 
 public class TabGroupRenderer extends RendererBase implements AjaxRenderer {
 
@@ -80,39 +75,29 @@
     int oldIndex = ((UITabGroup) component).getRenderedIndex();
 
     String clientId = component.getClientId(facesContext);
-    final Map parameters
-        = facesContext.getExternalContext().getRequestParameterMap();
+    final Map parameters = facesContext.getExternalContext().getRequestParameterMap();
     String newValue = (String) parameters.get(clientId + ACTIVE_INDEX_POSTFIX);
     try {
       int activeIndex = Integer.parseInt(newValue);
       if (activeIndex != oldIndex) {
-        ((UITabGroup) component).setActiveIndex(activeIndex);
-        TabChangeEvent event = new TabChangeEvent(component,
-            new Integer(oldIndex), new Integer(activeIndex));
-        event.setPhaseId(PhaseId.UPDATE_MODEL_VALUES);
+        TabChangeEvent event = new TabChangeEvent(component, oldIndex, activeIndex);
         component.queueEvent(event);
       }
-
     } catch (NumberFormatException e) {
       LOG.error("Can't parse activeIndex: '" + newValue + "'");
     }
   }
 
-  public void encodeEnd(FacesContext facesContext,
-                              UIComponent uiComponent) throws IOException {
+  public void encodeEnd(FacesContext facesContext, UIComponent uiComponent) throws IOException {
 
 
     UITabGroup component = (UITabGroup) uiComponent;
 
     HtmlRendererUtil.createHeaderAndBodyStyles(facesContext, component);
 
-    String image1x1
-        = ResourceManagerUtil.getImageWithPath(facesContext, "image/1x1.gif");
-
-    UIPanel[] tabs = component.getTabs();
-    layoutTabs(facesContext, component, tabs);
+    layoutTabs(facesContext, component);
 
-    final int activeIndex = component.getActiveIndex();
+    int activeIndex = ensureRenderedActiveIndex(component);
 
     final String clientId = component.getClientId(facesContext);
     final String hiddenId = clientId + TabGroupRenderer.ACTIVE_INDEX_POSTFIX;
@@ -142,49 +127,71 @@
     writer.writeIdAttribute(hiddenId);
     writer.endElement(HtmlConstants.INPUT);
 
+    String image1x1 = ResourceManagerUtil.getImageWithPath(facesContext, "image/1x1.gif");
+
     // if a outer uiPage is presend, the virtual tab will go over all
     // tabs and render it as they are selected, and it will
     // selected with stylesheet.
+    int virtualTab = 0;
+    //UIPanel[] tabs = component.getTabs();
+    for (UIComponent tab: (List<UIComponent>)component.getChildren()) {
+      if (tab instanceof UIPanel) {
+        if (tab.isRendered() && (SWITCH_TYPE_CLIENT.equals(switchType) || virtualTab == activeIndex)) {
+
+          if (virtualTab != activeIndex) {
+            HtmlRendererUtil.replaceStyleAttribute(component, "display", "none");
+          } else {
+            HtmlRendererUtil.removeStyleAttribute(component, "display");
+          }
 
-    for (int virtualTab = 0; virtualTab < tabs.length; virtualTab++) {
-
-      if (SWITCH_TYPE_CLIENT.equals(switchType) || virtualTab == activeIndex) {
-
-        if (virtualTab != activeIndex) {
-          HtmlRendererUtil.replaceStyleAttribute(component, "display", "none");
-        } else {
-          HtmlRendererUtil.removeStyleAttribute(component, "display");
+          writer.startElement(HtmlConstants.DIV, null);
+          writer.writeComment("empty div fix problem with mozilla and fieldset");
+          writer.endElement(HtmlConstants.DIV);
+
+          writer.startElement(HtmlConstants.DIV, null);
+          writer.writeIdAttribute(clientId);
+          renderTabGroupView(facesContext, writer, component, virtualTab,
+              (HtmlStyleMap) component.getAttributes().get(ATTR_STYLE),
+              switchType, image1x1);
+          writer.endElement(HtmlConstants.DIV);
+
+          if (TobagoConfig.getInstance(facesContext).isAjaxEnabled()
+              && SWITCH_TYPE_RELOAD_TAB.equals(switchType)) {
+            final String[] cmds = {
+                "new Tobago.TabGroup(",
+                "    '" + clientId + "', ",
+                "    '" + activeIndex + "');"
+            };
+            HtmlRendererUtil.writeScriptLoader(facesContext, new String[0], cmds);
+          }
         }
+        virtualTab++;
+      }
+    }
+  }
 
-        writer.startElement(HtmlConstants.DIV, null);
-        writer.writeComment("empty div fix problem with mozilla and fieldset");
-        writer.endElement(HtmlConstants.DIV);
-
-        writer.startElement(HtmlConstants.DIV, null);
-        writer.writeIdAttribute(clientId);
-        renderTabGroupView(facesContext, writer, component, virtualTab,
-            (HtmlStyleMap) component.getAttributes().get(ATTR_STYLE),
-            switchType, image1x1);
-        writer.endElement(HtmlConstants.DIV);
-
-        if (TobagoConfig.getInstance(facesContext).isAjaxEnabled()
-            && SWITCH_TYPE_RELOAD_TAB.equals(switchType)) {
-          final String[] cmds = {
-              "new Tobago.TabGroup(",
-              "    '" + clientId + "', ",
-              "    '" + activeIndex + "');"
-          };
-          HtmlRendererUtil.writeScriptLoader(facesContext, new String[0], cmds);
+  private int ensureRenderedActiveIndex(UITabGroup tabGroup) {
+    int activeIndex = tabGroup.getActiveIndex();
+    // ensure to select a rendered tab
+    int index = 0;
+    for (UIComponent tab: (List<UIComponent>)tabGroup.getChildren()) {
+      if (tab instanceof UIPanel) {
+        if (tab.isRendered()) {
+          if (activeIndex == index) {
+            break;
+          }
         }
+        index++;
       }
     }
+    tabGroup.setActiveIndex(index);
+    return index;
   }
 
   private void renderTabGroupView(
       FacesContext facesContext, TobagoResponseWriter writer, UITabGroup component,
       int virtualTab, HtmlStyleMap oStyle, String switchType, String image1x1)
       throws IOException {
-    UIPanel[] tabs = component.getTabs();
     writer.startElement(HtmlConstants.TABLE, null);
     writer.writeAttribute(HtmlAttributes.BORDER, "0", null);
     writer.writeAttribute(HtmlAttributes.CELLPADDING, "0", null);
@@ -211,74 +218,76 @@
 
     UIPanel activeTab = null;
 
-    for (int i = 0; i < tabs.length; i++) {
-      UIPanel tab = tabs[i];
-
-      String onclick;
-
-      if (TobagoConfig.getInstance(facesContext).isAjaxEnabled()
-          && SWITCH_TYPE_RELOAD_TAB.equals(switchType)) {
-        onclick = null;
-      }  else if (SWITCH_TYPE_RELOAD_PAGE.equals(switchType)
-          || SWITCH_TYPE_RELOAD_TAB.equals(switchType)) {
-        onclick = "tobago_requestTab('"
-            + clientId + "'," + i + ",'"
-            + ComponentUtil.findPage(component).getFormId(facesContext) + "')";
-      } else {   //  SWITCH_TYPE_CLIENT
-        onclick = "tobago_selectTab('"
-            + clientId + "'," + i + ','
-            + tabs.length + ')';
-      }
+    int index = 0;
+    for (UIComponent tab: (List<UIComponent>)component.getChildren()) {
+      if (tab instanceof UIPanel) {
+        if (tab.isRendered()) {
+          String onclick;
+          if (TobagoConfig.getInstance(facesContext).isAjaxEnabled()
+              && SWITCH_TYPE_RELOAD_TAB.equals(switchType)) {
+            onclick = null;
+          } else if (SWITCH_TYPE_RELOAD_PAGE.equals(switchType)
+              || SWITCH_TYPE_RELOAD_TAB.equals(switchType)) {
+            onclick = "tobago_requestTab('"
+                + clientId + "'," + index + ",'"
+                + ComponentUtil.findPage(component).getFormId(facesContext) + "')";
+          } else {   //  SWITCH_TYPE_CLIENT
+            onclick = "tobago_selectTab('"
+                + clientId + "'," + index + ','
+                + component.getChildCount() + ')';
+          }
 
-      LabelWithAccessKey label = new LabelWithAccessKey(tab);
+          LabelWithAccessKey label = new LabelWithAccessKey(tab);
 
-      String outerClass;
-      String innerClass;
-      if (virtualTab == i) {
-        outerClass = "tobago-tab-selected-outer";
-        innerClass = "tobago-tab-selected-inner";
-        activeTab = tab;
-      } else {
-        outerClass = "tobago-tab-unselected-outer";
-        innerClass = "tobago-tab-unselected-inner";
-      }
+          String outerClass;
+          String innerClass;
+          if (virtualTab == index) {
+            outerClass = "tobago-tab-selected-outer";
+            innerClass = "tobago-tab-selected-inner";
+            activeTab = (UIPanel) tab;
+          } else {
+            outerClass = "tobago-tab-unselected-outer";
+            innerClass = "tobago-tab-unselected-inner";
+          }
 
-      writer.startElement(HtmlConstants.TD, tab);
-      writer.writeIdAttribute(tab.getClientId(facesContext));
-      writer.writeAttribute(HtmlAttributes.TITLE, null, ATTR_TIP);
-
-      writer.startElement(HtmlConstants.DIV, null);
-      writer.writeClassAttribute(outerClass);
-
-      writer.startElement(HtmlConstants.DIV, null);
-      writer.writeClassAttribute(innerClass);
-
-      writer.startElement(HtmlConstants.SPAN, null);
-      writer.writeClassAttribute("tobago-tab-link");
-      String tabId = clientId + "." + virtualTab + SUBCOMPONENT_SEP + i;
-      writer.writeIdAttribute(tabId);
-      if (onclick != null) {
-        writer.writeAttribute(HtmlAttributes.ONCLICK, onclick, null);
-      }
-      if (label.getText() != null) {
-        HtmlRendererUtil.writeLabelWithAccessKey(writer, label);
-      } else {
-        writer.writeText(Integer.toString(i+1), null);
-      }
-      writer.endElement(HtmlConstants.SPAN);
+          writer.startElement(HtmlConstants.TD, tab);
+          writer.writeIdAttribute(tab.getClientId(facesContext));
+          writer.writeAttribute(HtmlAttributes.TITLE, null, ATTR_TIP);
+
+          writer.startElement(HtmlConstants.DIV, null);
+          writer.writeClassAttribute(outerClass);
+
+          writer.startElement(HtmlConstants.DIV, null);
+          writer.writeClassAttribute(innerClass);
+
+          writer.startElement(HtmlConstants.SPAN, null);
+          writer.writeClassAttribute("tobago-tab-link");
+          String tabId = clientId + "." + virtualTab + SUBCOMPONENT_SEP + index;
+          writer.writeIdAttribute(tabId);
+          if (onclick != null) {
+            writer.writeAttribute(HtmlAttributes.ONCLICK, onclick, null);
+          }
+          if (label.getText() != null) {
+            HtmlRendererUtil.writeLabelWithAccessKey(writer, label);
+          } else {
+            writer.writeText(Integer.toString(index+1), null);
+          }
+          writer.endElement(HtmlConstants.SPAN);
 
-      if (label.getAccessKey() != null) {
-        if (LOG.isWarnEnabled()
-            && !AccessKeyMap.addAccessKey(facesContext, label.getAccessKey())) {
-          LOG.warn("dublicated accessKey : " + label.getAccessKey());
+          if (label.getAccessKey() != null) {
+            if (LOG.isWarnEnabled()
+                && !AccessKeyMap.addAccessKey(facesContext, label.getAccessKey())) {
+              LOG.warn("dublicated accessKey : " + label.getAccessKey());
+            }
+            HtmlRendererUtil.addClickAcceleratorKey(
+                facesContext, tabId, label.getAccessKey());
+          }
+          writer.endElement(HtmlConstants.DIV);
+          writer.endElement(HtmlConstants.DIV);
+          writer.endElement(HtmlConstants.TD);
         }
-      HtmlRendererUtil.addClickAcceleratorKey(
-          facesContext, tabId, label.getAccessKey());
       }
-      writer.endElement(HtmlConstants.DIV);
-      writer.endElement(HtmlConstants.DIV);
-      writer.endElement(HtmlConstants.TD);
-
+      index++;
     }
 
     writer.startElement(HtmlConstants.TD, null);
@@ -326,7 +335,7 @@
     renderTabGroupView(context,
         (TobagoResponseWriter) context.getResponseWriter(),
         (UITabGroup) component,
-        ((UITabGroup) component).getActiveIndex(),
+        ensureRenderedActiveIndex((UITabGroup) component),
         (HtmlStyleMap) component.getAttributes().get(ATTR_STYLE),
         SWITCH_TYPE_RELOAD_TAB,
         ResourceManagerUtil.getImageWithPath(context, "image/1x1.gif"));
@@ -342,13 +351,13 @@
     if (height != -1) {
       fixedHeight = height;
     } else {
-      UIPanel[] tabs = component.getTabs();
       fixedHeight = 0;
-      for (int i = 0; i < tabs.length; i++) {
-        UIPanel tab = tabs[i];
-        RendererBase renderer = ComponentUtil.getRenderer(facesContext, tab);
-        fixedHeight
-            = Math.max(fixedHeight, renderer.getFixedHeight(facesContext, tab));
+      for (UIComponent tab: (List<UIComponent>)component.getChildren()) {
+        if (tab instanceof UIPanel && tab.isRendered()) {
+          RendererBase renderer = ComponentUtil.getRenderer(facesContext, tab);
+          fixedHeight
+              = Math.max(fixedHeight, renderer.getFixedHeight(facesContext, tab));
+        }
       }
       fixedHeight += getConfiguredValue(facesContext, component, "headerHeight");
       fixedHeight += getConfiguredValue(facesContext, component, "paddingHeight");
@@ -356,57 +365,22 @@
     return fixedHeight;
   }
 
-  private void layoutTabs(FacesContext facesContext, UITabGroup component,
-                          UIPanel[] tabs) {
+  private void layoutTabs(FacesContext facesContext, UITabGroup component) {
     Object layoutWidth =
         component.getAttributes().get(ATTR_LAYOUT_WIDTH);
     Object layoutHeight =
         component.getAttributes().get(ATTR_LAYOUT_HEIGHT);
 
-    for (int i = 0; i < tabs.length; i++) {
-      UIPanel tab = tabs[i];
-      if (layoutWidth != null) {
-        HtmlRendererUtil.layoutSpace(facesContext, tab, true);
-      }
-      if (layoutHeight != null) {
-        HtmlRendererUtil.layoutSpace(facesContext, tab, false);
-      }
-    }
-
-
-  }
-
-  public class TabController extends MethodBinding {
-
-    public static final String ID_PREFIX = "tab_";
-
-    public Object invoke(FacesContext facesContext, Object[] objects)
-        throws EvaluationException {
-
-      if (objects[0] instanceof ActionEvent) {
-        UICommand command  = (UICommand) ((ActionEvent) objects[0]).getSource();
-        if (LOG.isDebugEnabled()) {
-          LOG.debug("Id = " + command.getId());
+    for (UIComponent tab: (List<UIComponent>)component.getChildren()) {
+      if (tab instanceof UIPanel && tab.isRendered())  {
+        if (layoutWidth != null) {
+          HtmlRendererUtil.layoutSpace(facesContext, tab, true);
         }
-
-        if (command.getId() != null && command.getId().startsWith(ID_PREFIX)) {
-          try {
-            int newTab =
-                Integer.parseInt(command.getId().substring(ID_PREFIX.length()));
-          } catch (Exception e) {
-            // ignore
-          }
+        if (layoutHeight != null) {
+          HtmlRendererUtil.layoutSpace(facesContext, tab, false);
         }
       }
-      return null;
-    }
-
-    public Class getType(FacesContext facesContext)
-        throws MethodNotFoundException {
-      return String.class;
     }
-
   }
-
 }
 

Modified: myfaces/tobago/trunk/theme/scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/script/tab.js
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/script/tab.js?view=diff&rev=493439&r1=493438&r2=493439
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/script/tab.js (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/script/tab.js Sat Jan  6 02:03:37 2007
@@ -24,10 +24,12 @@
 
   for (i = 0; i < size; i++) {
     var tab = document.getElementById(controlId + '.' + i);
-    if (i == selectedIndex) {
-      tab.style.display='block';
-    } else {
-      tab.style.display='none';
+    if (tab) {
+      if (i == selectedIndex) {
+        tab.style.display='block';
+      } else {
+        tab.style.display='none';
+      }
     }
   }
 }

Modified: myfaces/tobago/trunk/theme/speyside/src/main/java/org/apache/myfaces/tobago/renderkit/html/speyside/standard/tag/TabGroupRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/speyside/src/main/java/org/apache/myfaces/tobago/renderkit/html/speyside/standard/tag/TabGroupRenderer.java?view=diff&rev=493439&r1=493438&r2=493439
==============================================================================
--- myfaces/tobago/trunk/theme/speyside/src/main/java/org/apache/myfaces/tobago/renderkit/html/speyside/standard/tag/TabGroupRenderer.java (original)
+++ myfaces/tobago/trunk/theme/speyside/src/main/java/org/apache/myfaces/tobago/renderkit/html/speyside/standard/tag/TabGroupRenderer.java Sat Jan  6 02:03:37 2007
@@ -59,7 +59,6 @@
       writer.writeAttribute(HtmlAttributes.STYLE, bodyStyle, null);
     }
 
-
     writer.startElement(HtmlConstants.DIV, null);
     writer.writeClassAttribute("tobago-tab-content");
 

Modified: myfaces/tobago/trunk/tobago-tool/gendoc/src/main/webapp/navigation.jsp
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/gendoc/src/main/webapp/navigation.jsp?view=diff&rev=493439&r1=493438&r2=493439
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/gendoc/src/main/webapp/navigation.jsp (original)
+++ myfaces/tobago/trunk/tobago-tool/gendoc/src/main/webapp/navigation.jsp Sat Jan  6 02:03:37 2007
@@ -92,7 +92,7 @@
     <tc:link link="screenshot/sheet.jsp"
              label="Sheet" target="View"/>
 
-    <%--<tc:link link="screenshot/tabGroup.jsp"  label="TabGroup"  target="View"/>--%>
+    <tc:link link="screenshot/tabGroup.jsp"  label="TabGroup"  target="View"/>
 
     <tc:link link="screenshot/textarea.jsp"
              label="Textarea" target="View"/>

Modified: myfaces/tobago/trunk/tobago-tool/gendoc/src/main/webapp/screenshot/tabGroup.jsp
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/gendoc/src/main/webapp/screenshot/tabGroup.jsp?view=diff&rev=493439&r1=493438&r2=493439
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/gendoc/src/main/webapp/screenshot/tabGroup.jsp (original)
+++ myfaces/tobago/trunk/tobago-tool/gendoc/src/main/webapp/screenshot/tabGroup.jsp Sat Jan  6 02:03:37 2007
@@ -14,4 +14,43 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
 --%>
-todo
+<%@ taglib uri="http://myfaces.apache.org/tobago/component" prefix="tc" %>
+<%@ taglib uri="http://myfaces.apache.org/tobago/extension" prefix="tx" %>
+<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
+<%@ taglib tagdir="/WEB-INF/tags/layout" prefix="layout" %>
+
+<layout:screenshot>
+  <jsp:body>
+    <f:subview id="button">
+      <tc:panel>
+        <f:facet name="layout">
+          <tc:gridLayout />
+        </f:facet>
+        <tc:tabGroup switchType="reloadPage" immediate="true">
+            <tc:tab label="tab1">
+              <tc:panel >
+                <f:facet name="layout">
+                  <tc:gridLayout rows="1*;fixed;fixed;1*" /></f:facet>
+                <tc:cell />
+                <tx:in label="label1" required="true" />
+                <tx:in label="label2" />
+                <tc:cell />
+              </tc:panel>
+            </tc:tab>
+            <tc:tab label="tab2" >
+              <tc:panel >
+                <f:facet name="layout">
+                  <tc:gridLayout rows="1*;fixed;fixed;1*" />
+                </f:facet>
+                <tc:cell />
+                <tx:in label="label1" />
+                <tx:in label="label2" />
+                <tc:cell />
+              </tc:panel>
+            </tc:tab>
+
+          </tc:tabGroup>
+      </tc:panel>
+    </f:subview>
+  </jsp:body>
+</layout:screenshot>
\ No newline at end of file