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/27 17:23:58 UTC

svn commit: r397565 - in /myfaces/tobago/trunk: core/src/main/java/org/apache/myfaces/tobago/component/ core/src/main/java/org/apache/myfaces/tobago/renderkit/ core/src/main/java/org/apache/myfaces/tobago/taglib/component/ core/src/main/resources/META-...

Author: weber
Date: Thu Apr 27 08:23:54 2006
New Revision: 397565

URL: http://svn.apache.org/viewcvs?rev=397565&view=rev
Log:
fix timeTag (set default converter)
fix getConvertedValue in SelectOneRendererBase
fix decoding of menuRadio component

Added:
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIMenuSelectOne.java
Modified:
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/SelectManyRendererBase.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/SelectOneRendererBase.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/TimeTag.java
    myfaces/tobago/trunk/core/src/main/resources/META-INF/faces-config.xml
    myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/MenuBarRenderer.java
    myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ToolBarRenderer.java

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java
URL: http://svn.apache.org/viewcvs/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java?rev=397565&r1=397564&r2=397565&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java Thu Apr 27 08:23:54 2006
@@ -55,7 +55,6 @@
 import javax.faces.application.Application;
 import javax.faces.component.ActionSource;
 import javax.faces.component.EditableValueHolder;
-
 import javax.faces.component.UICommand;
 import javax.faces.component.UIComponent;
 import javax.faces.component.UIGraphic;
@@ -675,12 +674,12 @@
     return column;
   }
 
-  public static UISelectOne createUISelectOneFacet(FacesContext facesContext, UICommand command) {
-    UISelectOne radio = null;
+  public static UIMenuSelectOne createUIMenuSelectOneFacet(FacesContext facesContext, UICommand command) {
+    UIMenuSelectOne radio = null;
     final ValueBinding valueBinding = command.getValueBinding(ATTR_VALUE);
     if (valueBinding != null) {
-      radio = (UISelectOne) createComponent(facesContext,
-          UISelectOne.COMPONENT_TYPE, RENDERER_TYPE_SELECT_ONE_RADIO);
+      radio = (UIMenuSelectOne) createComponent(facesContext,
+          UIMenuSelectOne.COMPONENT_TYPE, RENDERER_TYPE_SELECT_ONE_RADIO);
       command.getFacets().put(FACET_RADIO, radio);
       radio.setValueBinding(ATTR_VALUE, valueBinding);
     }

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java
URL: http://svn.apache.org/viewcvs/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java?rev=397565&r1=397564&r2=397565&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java Thu Apr 27 08:23:54 2006
@@ -47,7 +47,7 @@
  * Date: Mar 7, 2005
  * Time: 4:01:27 PM
  */
-public class Sorter extends MethodBinding {
+public class  Sorter extends MethodBinding {
 
   private static final Log LOG = LogFactory.getLog(Sorter.class);
 

Added: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIMenuSelectOne.java
URL: http://svn.apache.org/viewcvs/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIMenuSelectOne.java?rev=397565&view=auto
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIMenuSelectOne.java (added)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIMenuSelectOne.java Thu Apr 27 08:23:54 2006
@@ -0,0 +1,32 @@
+package org.apache.myfaces.tobago.component;
+
+/*
+ * Copyright 2002-2005 The Apache Software Foundation.
+ * 
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ * 
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+import java.util.List;
+
+public class UIMenuSelectOne extends javax.faces.component.UISelectOne {
+
+  public static final String COMPONENT_TYPE
+      = "org.apache.myfaces.tobago.MenuSelectOne";
+
+  // hack to made decoding of menuRadio work
+  // selectItems are located at parent component
+  public List getChildren() {
+    return getParent().getChildren();
+  }
+
+}

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/SelectManyRendererBase.java
URL: http://svn.apache.org/viewcvs/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/SelectManyRendererBase.java?rev=397565&r1=397564&r2=397565&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/SelectManyRendererBase.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/SelectManyRendererBase.java Thu Apr 27 08:23:54 2006
@@ -20,9 +20,16 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.myfaces.tobago.component.ComponentUtil;
 
+import javax.faces.FacesException;
 import javax.faces.component.UIComponent;
 import javax.faces.component.UISelectMany;
 import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
+import javax.faces.el.ValueBinding;
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.List;
 
 public class SelectManyRendererBase extends RendererBase {
 
@@ -52,8 +59,166 @@
       newValues = new String[0]; // because no selection will not submitted by browsers
     }
     uiSelectMany.setSubmittedValue(newValues);
-    uiSelectMany.setValid(true);
 
   }
+
+  // the following is copied from myfaces shared RendererUtils
+  public Object getConvertedValue(FacesContext facesContext, UIComponent component, Object submittedValue) throws ConverterException {
+
+    if (submittedValue == null)
+    {
+      return null;
+    }
+    else
+    {
+      if (!(submittedValue instanceof String[]))
+      {
+        throw new ConverterException("Submitted value of type String[] for component : "
+            + component.getClientId(facesContext) + "expected");
+      }
+    }
+    return getConvertedUISelectManyValue(facesContext, (UISelectMany) component, (String[]) submittedValue);
+  }
+
+  private Object getConvertedUISelectManyValue(FacesContext facesContext,
+                                               UISelectMany component,
+                                               String[] submittedValue)
+            throws ConverterException
+    {
+        // Attention!
+        // This code is duplicated in jsfapi component package.
+        // If you change something here please do the same in the other class!
+
+        if (submittedValue == null) throw new NullPointerException("submittedValue");
+
+        ValueBinding vb = component.getValueBinding("value");
+        Class valueType = null;
+        Class arrayComponentType = null;
+        if (vb != null)
+        {
+            valueType = vb.getType(facesContext);
+            if (valueType != null && valueType.isArray())
+            {
+                arrayComponentType = valueType.getComponentType();
+            }
+        }
+
+        Converter converter = component.getConverter();
+        if (converter == null)
+        {
+            if (valueType == null)
+            {
+                // No converter, and no idea of expected type
+                // --> return the submitted String array
+                return submittedValue;
+            }
+
+            if (List.class.isAssignableFrom(valueType))
+            {
+                // expected type is a List
+                // --> according to javadoc of UISelectMany we assume that the element type
+                //     is java.lang.String, and copy the String array to a new List
+                int len = submittedValue.length;
+                List lst = new ArrayList(len);
+                for (int i = 0; i < len; i++)
+                {
+                    lst.add(submittedValue[i]);
+                }
+                return lst;
+            }
+
+            if (arrayComponentType == null)
+            {
+                throw new IllegalArgumentException("ValueBinding for UISelectMany must be of type List or Array");
+            }
+
+            if (String.class.equals(arrayComponentType)) return submittedValue; //No conversion needed for String type
+            if (Object.class.equals(arrayComponentType)) return submittedValue; //No conversion for Object class
+
+            try
+            {
+                converter = facesContext.getApplication().createConverter(arrayComponentType);
+            }
+            catch (FacesException e)
+            {
+                LOG.error("No Converter for type " + arrayComponentType.getName() + " found", e);
+                return submittedValue;
+            }
+        }
+
+        // Now, we have a converter...
+        // We determine the type of the component array after converting one of it's elements
+        if (vb != null)
+        {
+            valueType = vb.getType(facesContext);
+            if (valueType != null && valueType.isArray())
+            {
+                if (submittedValue.length > 0)
+                {
+                    arrayComponentType = converter.getAsObject(facesContext, component, submittedValue[0]).getClass();
+                }
+            }
+        }
+
+        if (valueType == null)
+        {
+            // ...but have no idea of expected type
+            // --> so let's convert it to an Object array
+            int len = submittedValue.length;
+            Object [] convertedValues = (Object []) Array.newInstance(
+                    arrayComponentType==null?Object.class:arrayComponentType,len);
+            for (int i = 0; i < len; i++)
+            {
+                convertedValues[i]
+                    = converter.getAsObject(facesContext, component, submittedValue[i]);
+            }
+            return convertedValues;
+        }
+
+        if (List.class.isAssignableFrom(valueType))
+        {
+            // Curious case: According to specs we should assume, that the element type
+            // of this List is java.lang.String. But there is a Converter set for this
+            // component. Because the user must know what he is doing, we will convert the values.
+            int len = submittedValue.length;
+            List lst = new ArrayList(len);
+            for (int i = 0; i < len; i++)
+            {
+                lst.add(converter.getAsObject(facesContext, component, submittedValue[i]));
+            }
+            return lst;
+        }
+
+        if (arrayComponentType == null)
+        {
+            throw new IllegalArgumentException("ValueBinding for UISelectMany must be of type List or Array");
+        }
+
+        if (arrayComponentType.isPrimitive())
+        {
+            //primitive array
+            int len = submittedValue.length;
+            Object convertedValues = Array.newInstance(arrayComponentType, len);
+            for (int i = 0; i < len; i++)
+            {
+                Array.set(convertedValues, i,
+                          converter.getAsObject(facesContext, component, submittedValue[i]));
+            }
+            return convertedValues;
+        }
+        else
+        {
+            //Object array
+            int len = submittedValue.length;
+            ArrayList convertedValues = new ArrayList(len);
+            for (int i = 0; i < len; i++)
+            {
+                convertedValues.add(i, converter.getAsObject(facesContext, component, submittedValue[i]));
+            }
+            return convertedValues.toArray((Object[]) Array.newInstance(arrayComponentType, len));
+        }
+    }
+
 }
+
 

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/SelectOneRendererBase.java
URL: http://svn.apache.org/viewcvs/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/SelectOneRendererBase.java?rev=397565&r1=397564&r2=397565&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/SelectOneRendererBase.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/SelectOneRendererBase.java Thu Apr 27 08:23:54 2006
@@ -44,7 +44,6 @@
       LOG.debug("decode: key='" + clientId + "' value='" + newValue + "'");
     }
     uiSelectOne.setSubmittedValue(newValue);
-    uiSelectOne.setValid(true);
   }
 
 

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/TimeTag.java
URL: http://svn.apache.org/viewcvs/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/TimeTag.java?rev=397565&r1=397564&r2=397565&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/TimeTag.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/TimeTag.java Thu Apr 27 08:23:54 2006
@@ -18,7 +18,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.myfaces.tobago.component.UIInput;
+import org.apache.myfaces.tobago.component.UITimeInput;
 
 import javax.faces.component.UIComponent;
 import javax.servlet.jsp.JspException;
@@ -28,7 +28,7 @@
   private static final Log LOG = LogFactory.getLog(TimeTag.class);
 
   public String getComponentType() {
-    return UIInput.COMPONENT_TYPE;
+    return UITimeInput.COMPONENT_TYPE;
   }
 
   public int doEndTag() throws JspException {

Modified: myfaces/tobago/trunk/core/src/main/resources/META-INF/faces-config.xml
URL: http://svn.apache.org/viewcvs/myfaces/tobago/trunk/core/src/main/resources/META-INF/faces-config.xml?rev=397565&r1=397564&r2=397565&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/resources/META-INF/faces-config.xml (original)
+++ myfaces/tobago/trunk/core/src/main/resources/META-INF/faces-config.xml Thu Apr 27 08:23:54 2006
@@ -98,6 +98,10 @@
     <component-type>org.apache.myfaces.tobago.MenuCommand</component-type>
     <component-class>org.apache.myfaces.tobago.component.UIMenuCommand</component-class>
   </component>
+ <component>
+    <component-type>org.apache.myfaces.tobago.MenuSelectOne</component-type>
+    <component-class>org.apache.myfaces.tobago.component.UIMenuSelectOne</component-class>
+  </component>
   <component>
     <component-type>org.apache.myfaces.tobago.MenuSeparator</component-type>
     <component-class>org.apache.myfaces.tobago.component.UIMenuSeparator</component-class>

Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/MenuBarRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/MenuBarRenderer.java?rev=397565&r1=397564&r2=397565&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/MenuBarRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/MenuBarRenderer.java Thu Apr 27 08:23:54 2006
@@ -39,6 +39,7 @@
 import org.apache.myfaces.tobago.component.ComponentUtil;
 import org.apache.myfaces.tobago.component.UIMenu;
 import org.apache.myfaces.tobago.component.UIMenuCommand;
+import org.apache.myfaces.tobago.component.UIMenuSelectOne;
 import org.apache.myfaces.tobago.component.UIMenuSeparator;
 import org.apache.myfaces.tobago.component.UIPage;
 import org.apache.myfaces.tobago.component.UISelectBooleanCommand;
@@ -57,7 +58,6 @@
 import javax.faces.component.UICommand;
 import javax.faces.component.UIComponent;
 import javax.faces.component.UIPanel;
-import javax.faces.component.UISelectOne;
 import javax.faces.context.FacesContext;
 import javax.faces.context.ResponseWriter;
 import javax.faces.model.SelectItem;
@@ -97,6 +97,17 @@
         writer.writeAttribute("style", null, ATTR_STYLE);
       }
       writer.writeClassAttribute(cssClasses);
+/*
+
+      writer.startElement("span");
+      writer.writeAttribute("style", "position: relative", null);
+//      writer.writeClassAttribute("tobago-menuBar-container");
+
+      renderTopLevelItems(facesContext, writer, component);
+
+      writer.endElement("span");
+      
+*/
       writer.endElement("div");
     }
     attributes.put(MENU_ACCELERATOR_KEYS, new ArrayList<String>());
@@ -113,6 +124,20 @@
     }
   }
 
+  private void renderTopLevelItems(FacesContext facesContext,
+      TobagoResponseWriter writer, UIComponent component) throws IOException {
+    String bac = "green;";
+    for (Object o : component.getChildren()) {
+      if (o instanceof UIMenu) {
+        writer.startElement("span");
+        writer.writeAttribute("style", "position: relative; background: " + bac + ";", null);
+        writeMenuEntry(facesContext, writer, (UIMenu)o);
+        writer.endElement("span");
+        bac = "lime";
+      }
+    }
+  }
+
   protected void addScriptsAndStyles(FacesContext facesContext,
                                      UIComponent component, final String clientId, String setupFunction,
                                      String scriptBlock) throws IOException {
@@ -203,6 +228,21 @@
 
   private String createMenuEntry(FacesContext facesContext, UIPanel uiPanel)
       throws IOException {
+    ResponseWriter savedWriter = facesContext.getResponseWriter();
+    StringWriter stringWriter = new StringWriter();
+    TobagoResponseWriter writer
+        = (TobagoResponseWriter) savedWriter.cloneWithWriter(stringWriter);
+    facesContext.setResponseWriter(writer);
+
+    writeMenuEntry(facesContext, writer, uiPanel);
+
+    facesContext.setResponseWriter(savedWriter);
+
+
+    return "new Tobago.Menu.Item('" + removeLFs(stringWriter.toString()) + "', null)";
+  }
+
+  private void writeMenuEntry(FacesContext facesContext, TobagoResponseWriter writer, UIPanel uiPanel) throws IOException {
     final boolean disabled
         = ComponentUtil.getBooleanAttribute(uiPanel, ATTR_DISABLED);
     final boolean topMenu = (uiPanel.getParent().getRendererType() != null)
@@ -220,12 +260,6 @@
     String image = (String) uiPanel.getAttributes().get(ATTR_IMAGE);
 
 
-    ResponseWriter savedWriter = facesContext.getResponseWriter();
-    StringWriter stringWriter = new StringWriter();
-    TobagoResponseWriter writer
-        = (TobagoResponseWriter) savedWriter.cloneWithWriter(stringWriter);
-    facesContext.setResponseWriter(writer);
-
     addImage(writer, facesContext, image, disabled);
 
     writer.startElement("a", null);
@@ -249,17 +283,6 @@
       HtmlRendererUtil.writeLabelWithAccessKey(writer, label);
     }
     writer.endElement("a");
-
-    if (!topMenu) {
-      // uiPanel is a submenu
-//      addSubItemMarker(writer, facesContext);
-    }
-
-
-    facesContext.setResponseWriter(savedWriter);
-
-
-    return "new Tobago.Menu.Item('" + removeLFs(stringWriter.toString()) + "', null)";
   }
 
   private void addAcceleratorKey(
@@ -394,9 +417,9 @@
     LabelWithAccessKey label = new LabelWithAccessKey(command);
 
 
-    UISelectOne radio = (UISelectOne) command.getFacet(FACET_RADIO);
+    UIMenuSelectOne radio = (UIMenuSelectOne) command.getFacet(FACET_RADIO);
     if (radio == null) {
-      radio = ComponentUtil.createUISelectOneFacet(facesContext, command);
+      radio = ComponentUtil.createUIMenuSelectOneFacet(facesContext, command);
       radio.setId(facesContext.getViewRoot().createUniqueId());
     }
 

Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ToolBarRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ToolBarRenderer.java?rev=397565&r1=397564&r2=397565&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ToolBarRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ToolBarRenderer.java Thu Apr 27 08:23:54 2006
@@ -42,6 +42,7 @@
 import static org.apache.myfaces.tobago.TobagoConstants.RENDERER_TYPE_MENUBAR;
 import static org.apache.myfaces.tobago.TobagoConstants.SUBCOMPONENT_SEP;
 import org.apache.myfaces.tobago.component.ComponentUtil;
+import org.apache.myfaces.tobago.component.UIMenuSelectOne;
 import org.apache.myfaces.tobago.component.UISelectBooleanCommand;
 import org.apache.myfaces.tobago.component.UISelectOneCommand;
 import org.apache.myfaces.tobago.context.ResourceManager;
@@ -59,7 +60,6 @@
 import javax.faces.component.UICommand;
 import javax.faces.component.UIComponent;
 import javax.faces.component.UIPanel;
-import javax.faces.component.UISelectOne;
 import javax.faces.component.UIViewRoot;
 import javax.faces.context.FacesContext;
 import javax.faces.model.SelectItem;
@@ -156,9 +156,9 @@
 
     List<SelectItem> items = ComponentUtil.getSelectItems(command);
 
-    UISelectOne radio = (UISelectOne) command.getFacet(FACET_RADIO);
+    UIMenuSelectOne radio = (UIMenuSelectOne) command.getFacet(FACET_RADIO);
     if (radio == null) {
-      radio = ComponentUtil.createUISelectOneFacet(facesContext, command);
+      radio = ComponentUtil.createUIMenuSelectOneFacet(facesContext, command);
       radio.setId(facesContext.getViewRoot().createUniqueId());
     }