You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by we...@apache.org on 2006/04/08 00:10:16 UTC

svn commit: r392437 - in /incubator/tobago/trunk: core/src/main/java/org/apache/myfaces/tobago/component/ core/src/main/java/org/apache/myfaces/tobago/taglib/component/ theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarboroug...

Author: weber
Date: Fri Apr  7 15:10:14 2006
New Revision: 392437

URL: http://svn.apache.org/viewcvs?rev=392437&view=rev
Log:
part of TOBAGO-1 (Clean up Tag-Classes and create appropriate UIComponent-Classes)

Modified:
    incubator/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UITabGroup.java
    incubator/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/TabGroupTag.java
    incubator/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.java

Modified: incubator/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UITabGroup.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UITabGroup.java?rev=392437&r1=392436&r2=392437&view=diff
==============================================================================
--- incubator/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UITabGroup.java (original)
+++ incubator/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UITabGroup.java Fri Apr  7 15:10:14 2006
@@ -50,6 +50,8 @@
   private int activeIndex;
   private int renderedIndex;
 
+  private String switchType = SWITCH_TYPE_CLIENT;
+
   private MethodBinding tabChangeListener = null;
   public static final String SWITCH_TYPE_CLIENT = "client";
   public static final String SWITCH_TYPE_RELOAD_PAGE = "reloadPage";
@@ -67,7 +69,7 @@
     Object state
         = stateBinding != null ? stateBinding.getValue(facesContext) : null;
     if (state instanceof Integer) {
-      activeIndex = ((Integer) state).intValue();
+      activeIndex = (Integer) state;
     } else if (state != null) {
       LOG.warn("Illegal class in stateBinding: " + state.getClass().getName());
     }
@@ -214,8 +216,6 @@
   }
 
   private boolean isClientType() {
-    final String switchType
-        = ComponentUtil.getStringAttribute(this, ATTR_SWITCH_TYPE);
     return (switchType == null || switchType.equals(SWITCH_TYPE_CLIENT));
   }
 
@@ -228,20 +228,22 @@
   }
 
   public Object saveState(FacesContext context) {
-    Object[] state = new Object[4];
+    Object[] state = new Object[5];
     state[0] = super.saveState(context);
-    state[1] = new Integer(renderedIndex);
-    state[2] = new Integer(activeIndex);
+    state[1] = renderedIndex;
+    state[2] = activeIndex;
     state[3] = saveAttachedState(context, tabChangeListener);
+    state[4] = switchType;
     return state;
   }
 
   public void restoreState(FacesContext context, Object state) {
     Object[] values = (Object[]) state;
     super.restoreState(context, values[0]);
-    renderedIndex = ((Integer) values[1]).intValue();
-    activeIndex = ((Integer) values[2]).intValue();
+    renderedIndex = (Integer) values[1];
+    activeIndex = (Integer) values[2];
     tabChangeListener = (MethodBinding) restoreAttachedState(context, values[3]);
+    switchType = (String) values[4];
   }
 
   public void encodeAjax(FacesContext facesContext) throws IOException {
@@ -251,7 +253,7 @@
       Object state
           = stateBinding != null ? stateBinding.getValue(facesContext) : null;
       if (state instanceof Integer) {
-        activeIndex = ((Integer) state).intValue();
+        activeIndex = (Integer) state;
       } else if (state != null) {
         LOG.warn("Illegal class in stateBinding: " + state.getClass().getName());
       }
@@ -275,5 +277,31 @@
 
   public int getRenderedIndex() {
     return renderedIndex;
+  }
+
+  public String getSwitchType() {
+    String value = null;
+    if (switchType != null) {
+      value = switchType;
+    } else {
+      ValueBinding vb = getValueBinding(ATTR_SWITCH_TYPE);
+      if (vb != null) {
+        value = (String) vb.getValue(FacesContext.getCurrentInstance());
+      }
+    }
+
+    if (SWITCH_TYPE_CLIENT.equals(value)
+        || SWITCH_TYPE_RELOAD_PAGE.equals(value)
+        || SWITCH_TYPE_RELOAD_TAB.equals(value)) {
+      return value;
+    } else {
+      LOG.warn("Illegal value for attribute switchtype : " + switchType
+          + " Using default value " + SWITCH_TYPE_CLIENT);
+      return SWITCH_TYPE_CLIENT ;
+    }
+  }
+
+  public void setSwitchType(String switchType) {
+    this.switchType = switchType;
   }
 }

Modified: incubator/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/TabGroupTag.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/TabGroupTag.java?rev=392437&r1=392436&r2=392437&view=diff
==============================================================================
--- incubator/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/TabGroupTag.java (original)
+++ incubator/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/TabGroupTag.java Fri Apr  7 15:10:14 2006
@@ -29,7 +29,6 @@
 import org.apache.myfaces.tobago.component.UITabGroup;
 import static org.apache.myfaces.tobago.component.UITabGroup.SWITCH_TYPE_CLIENT;
 import static org.apache.myfaces.tobago.component.UITabGroup.SWITCH_TYPE_RELOAD_PAGE;
-import static org.apache.myfaces.tobago.component.UITabGroup.SWITCH_TYPE_RELOAD_TAB;
 import org.apache.myfaces.tobago.taglib.decl.HasDeprecatedDimension;
 import org.apache.myfaces.tobago.taglib.decl.HasIdBindingAndRendered;
 import org.apache.myfaces.tobago.taglib.decl.HasState;
@@ -49,7 +48,6 @@
 
   private static final Log LOG = LogFactory.getLog(TabGroupTag.class);
 
-  private String serverside;
   private String state;
   private String switchType;
 
@@ -62,41 +60,17 @@
   protected void setProperties(UIComponent component) {
     super.setProperties(component);
     ComponentUtil.setValueBinding(component, ATTR_STATE, state);
-    if (switchType != null) {
-
-      if (SWITCH_TYPE_RELOAD_PAGE.equals(switchType)) {
-        ComponentUtil.setStringProperty(component, ATTR_SWITCH_TYPE, SWITCH_TYPE_RELOAD_PAGE);
-      } else if (SWITCH_TYPE_RELOAD_TAB.equals(switchType)) {
-        ComponentUtil.setStringProperty(component, ATTR_SWITCH_TYPE, SWITCH_TYPE_RELOAD_TAB);
-      } else if (SWITCH_TYPE_CLIENT.equals(switchType)) {
-        ComponentUtil.setStringProperty(component, ATTR_SWITCH_TYPE, SWITCH_TYPE_CLIENT);
-      } else {
-        LOG.warn("Illegal switchType value: \"" + switchType + "\" using default: \"" + SWITCH_TYPE_CLIENT + "\"");
-        ComponentUtil.setStringProperty(component, ATTR_SWITCH_TYPE, SWITCH_TYPE_CLIENT);
-      }
-    } else {
-      if (Boolean.valueOf(serverside)) {
-        ComponentUtil.setStringProperty(component, ATTR_SWITCH_TYPE, SWITCH_TYPE_RELOAD_PAGE);
-      } else {
-        ComponentUtil.setStringProperty(component, ATTR_SWITCH_TYPE, SWITCH_TYPE_CLIENT);
-      }
-    }
-
+    ComponentUtil.setStringProperty(component, ATTR_SWITCH_TYPE, switchType);
   }
 
   @Override
   public void release() {
     super.release();
-    serverside = null;
     state = null;
   }
 
-  public String getServerside() {
-    return serverside;
-  }
-
-
   /**
+   * Deprecated! Use 'switchType' instead.
    * Flag indicating that tab switching is done by server request.
    * @deprecated
    */
@@ -104,7 +78,9 @@
   @UIComponentTagAttribute(type = "java.lang.Boolean", defaultValue = "false")
   @Deprecated
   public void setServerside(String serverside) {
-    this.serverside = serverside;
+    LOG.warn("Attribute 'serverside' is deprecated! Use 'switchType' instead.");
+    this.switchType = Boolean.valueOf(serverside)
+        ? SWITCH_TYPE_RELOAD_PAGE : SWITCH_TYPE_CLIENT;
   }
 
   public void setState(String state) {
@@ -120,7 +96,7 @@
    *   "reloadTab"  : Tab switching id done by server request. Only the Tab is reloaded.
    */
   @TagAttribute
-  @UIComponentTagAttribute(type = "java.lang.String", defaultValue = SWITCH_TYPE_CLIENT)
+  @UIComponentTagAttribute(type = "java.lang.String", defaultValue = "client")
   public void setSwitchType(String switchType) {
     this.switchType = switchType;
   }

Modified: incubator/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.java?rev=392437&r1=392436&r2=392437&view=diff
==============================================================================
--- incubator/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.java (original)
+++ incubator/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TabGroupRenderer.java Fri Apr  7 15:10:14 2006
@@ -29,7 +29,6 @@
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_STYLE;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_STYLE_BODY;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_STYLE_HEADER;
-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SWITCH_TYPE;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_TIP;
 import static org.apache.myfaces.tobago.TobagoConstants.SUBCOMPONENT_SEP;
 import org.apache.myfaces.tobago.ajax.api.AjaxRenderer;
@@ -115,7 +114,7 @@
     final String clientId = component.getClientId(facesContext);
     final String hiddenId = clientId + TabGroupRenderer.ACTIVE_INDEX_POSTFIX;
 
-    final String switchType = ComponentUtil.getStringAttribute(component, ATTR_SWITCH_TYPE);
+    final String switchType = component.getSwitchType();
 
     UIPage page = ComponentUtil.findPage(component);
     page.getScriptFiles().add("script/tab.js");