You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2010/04/23 23:05:17 UTC

svn commit: r937519 - in /myfaces/tobago/trunk: core/src/main/java/org/apache/myfaces/tobago/taglib/component/ core/src/main/java/org/apache/myfaces/tobago/util/ example/test/src/main/java/org/apache/myfaces/tobago/example/test/ example/test/src/main/w...

Author: lofwyr
Date: Fri Apr 23 21:05:16 2010
New Revision: 937519

URL: http://svn.apache.org/viewvc?rev=937519&view=rev
Log:
TOBAGO-877: Better support of typed literals in <tc:selectItem> and <f:selectItem>

Added:
    myfaces/tobago/trunk/example/test/src/main/java/org/apache/myfaces/tobago/example/test/SelectItemModel.java
      - copied unchanged from r937509, myfaces/tobago/branches/tobago-1.0.x/example/test/src/main/java/org/apache/myfaces/tobago/example/test/SelectItemModel.java
    myfaces/tobago/trunk/example/test/src/main/webapp/tc/selectItem/
      - copied from r937504, myfaces/tobago/branches/tobago-1.0.x/example/test/src/main/webapp/tc/selectItem/
Modified:
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/SelectItemTagDeclaration.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java
    myfaces/tobago/trunk/example/test/src/main/webapp/WEB-INF/faces-config.xml
    myfaces/tobago/trunk/example/test/src/main/webapp/tc/selectItem/type-of-literals.xhtml
    myfaces/tobago/trunk/theme/standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtils.java

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/SelectItemTagDeclaration.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/SelectItemTagDeclaration.java?rev=937519&r1=937518&r2=937519&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/SelectItemTagDeclaration.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/SelectItemTagDeclaration.java Fri Apr 23 21:05:16 2010
@@ -41,7 +41,7 @@ import org.apache.myfaces.tobago.taglib.
 @Tag(name = "selectItem", bodyContent = BodyContent.EMPTY)
 @UIComponentTag(
     uiComponent = "org.apache.myfaces.tobago.component.UISelectItem",
-    uiComponentBaseClass = "javax.faces.component.UISelectItem",
+    uiComponentBaseClass = "org.apache.myfaces.tobago.internal.component.AbstractUISelectItem",
     allowedChildComponenents = "NONE")
 public interface SelectItemTagDeclaration extends HasBinding, HasId, HasMarkup, HasItemLabel {
   /**

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java?rev=937519&r1=937518&r2=937519&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java Fri Apr 23 21:05:16 2010
@@ -738,4 +738,32 @@ public class ComponentUtils {
     return StringUtils.split(renderers, LIST_SEPARATOR_CHARS);
   }
 
+  public static Object getConvertedValue(
+      FacesContext facesContext, javax.faces.component.UIInput component, String stringValue) {
+    try {
+      Renderer renderer = getRenderer(facesContext, component);
+      if (renderer != null) {
+        return renderer.getConvertedValue(facesContext, component, stringValue);
+      } else {
+        Converter converter = component.getConverter();
+        if (converter == null) {
+          //Try to find out by value binding
+          ValueBinding vb = component.getValueBinding("value");
+          if (vb != null) {
+            Class valueType = vb.getType(facesContext);
+            if (valueType != null) {
+              converter = facesContext.getApplication().createConverter(valueType);
+            }
+          }
+        }
+        if (converter != null) {
+          converter.getAsObject(facesContext, component, stringValue);
+        }
+      }
+    } catch (Exception e) {
+      LOG.warn("Can't convert string value '" + stringValue + "'", e);
+    }
+    return stringValue;
+  }
+
 }

Modified: myfaces/tobago/trunk/example/test/src/main/webapp/WEB-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/test/src/main/webapp/WEB-INF/faces-config.xml?rev=937519&r1=937518&r2=937519&view=diff
==============================================================================
--- myfaces/tobago/trunk/example/test/src/main/webapp/WEB-INF/faces-config.xml (original)
+++ myfaces/tobago/trunk/example/test/src/main/webapp/WEB-INF/faces-config.xml Fri Apr 23 21:05:16 2010
@@ -78,6 +78,12 @@
   </managed-bean>
 
   <managed-bean>
+    <managed-bean-name>selectItemModel</managed-bean-name>
+    <managed-bean-class>org.apache.myfaces.tobago.example.test.SelectItemModel</managed-bean-class>
+    <managed-bean-scope>session</managed-bean-scope>
+  </managed-bean>
+
+  <managed-bean>
     <managed-bean-name>reload</managed-bean-name>
     <managed-bean-class>org.apache.myfaces.tobago.example.test.Reload</managed-bean-class>
     <managed-bean-scope>session</managed-bean-scope>

Modified: myfaces/tobago/trunk/example/test/src/main/webapp/tc/selectItem/type-of-literals.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/test/src/main/webapp/tc/selectItem/type-of-literals.xhtml?rev=937519&r1=937504&r2=937519&view=diff
==============================================================================
--- myfaces/tobago/trunk/example/test/src/main/webapp/tc/selectItem/type-of-literals.xhtml (original)
+++ myfaces/tobago/trunk/example/test/src/main/webapp/tc/selectItem/type-of-literals.xhtml Fri Apr 23 21:05:16 2010
@@ -25,7 +25,7 @@
 
   <tc:page width="700px" height="600px">
     <f:facet name="layout">
-      <tc:gridLayout rows="fixed;80px;80px;fixed;*" columns="4*;*"/>
+      <tc:gridLayout rows="auto;80px;80px;auto;*" columns="4*;*"/>
     </f:facet>
 
     <tc:cell spanX="2">

Modified: myfaces/tobago/trunk/theme/standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtils.java?rev=937519&r1=937518&r2=937519&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtils.java (original)
+++ myfaces/tobago/trunk/theme/standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/util/HtmlRendererUtils.java Fri Apr 23 21:05:16 2010
@@ -389,7 +389,11 @@ public final class HtmlRendererUtils {
         writer.endElement(HtmlConstants.OPTGROUP);
       } else {
         writer.startElement(HtmlConstants.OPTION, null);
-        final Object itemValue = item.getValue();
+        Object itemValue = item.getValue();
+        // when using selectItem tag with a literal value: use the converted value
+        if (itemValue instanceof String && values.length > 0 && !(values[0] instanceof String)) {
+          itemValue = ComponentUtils.getConvertedValue(facesContext, component, (String)itemValue);
+        }
         String formattedValue = RenderUtil.getFormattedValue(facesContext, component, itemValue);
         writer.writeAttribute(HtmlAttributes.VALUE, formattedValue, true);
         if (item instanceof org.apache.myfaces.tobago.model.SelectItem) {
@@ -406,7 +410,7 @@ public final class HtmlRendererUtils {
             writer.writeClassAttribute(optionStyle);
           }
         }
-        if (RenderUtil.contains(values, item.getValue())) {
+        if (RenderUtil.contains(values, itemValue)) {
           writer.writeAttribute(HtmlAttributes.SELECTED, true);
         }
         if (item.isDisabled()) {