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 2016/06/15 12:15:45 UTC

svn commit: r1748568 - in /myfaces/tobago/trunk: tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/ tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/ tobago-core/src/main/java/org/apache/myfaces/tobago/util/ tobago-exa...

Author: lofwyr
Date: Wed Jun 15 12:15:45 2016
New Revision: 1748568

URL: http://svn.apache.org/viewvc?rev=1748568&view=rev
Log:
TOBAGO-1567: Clean up: consolidate getFormattedValue() and other methods.
* more robust type detection (there was a problem with parameters in EL)
* QUnit Tests

Modified:
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIDate.java
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/RendererBase.java
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java
    myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/CurrentValueController.java
    myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/50000-java/10-rendererBase-getCurrentValue/rendererBase-getCurrentValue.test.js
    myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/50000-java/10-rendererBase-getCurrentValue/rendererBase-getCurrentValue.xhtml
    myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/test/java/org/apache/myfaces/tobago/example/demo/QUnitTests.java

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIDate.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIDate.java?rev=1748568&r1=1748567&r2=1748568&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIDate.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIDate.java Wed Jun 15 12:15:45 2016
@@ -35,7 +35,7 @@ public abstract class AbstractUIDate ext
   public String getPattern() {
     String pattern = null;
     final FacesContext facesContext = getFacesContext();
-    final Converter converter = ComponentUtils.getConverter(facesContext, this);
+    final Converter converter = ComponentUtils.getConverter(facesContext, this, getSubmittedValue());
     if (converter instanceof DateTimeConverter) {
       pattern = DateFormatUtils.findPattern((DateTimeConverter) converter);
     }

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/RendererBase.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/RendererBase.java?rev=1748568&r1=1748567&r2=1748568&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/RendererBase.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/RendererBase.java Wed Jun 15 12:15:45 2016
@@ -79,7 +79,7 @@ public class RendererBase extends Render
     if (!(submittedValue instanceof String)) {
       return submittedValue;
     }
-    final Converter converter = ComponentUtils.getConverter(context, component);
+    final Converter converter = ComponentUtils.getConverter(context, component, submittedValue);
     if (converter != null) {
       return converter.getAsObject(context, component, (String) submittedValue);
     } else {

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java?rev=1748568&r1=1748567&r2=1748568&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ComponentUtils.java Wed Jun 15 12:15:45 2016
@@ -821,7 +821,8 @@ public final class ComponentUtils {
     return map != null ? map.get(name) : null;
   }
 
-  public static Converter getConverter(final FacesContext facesContext, final UIComponent component) {
+  public static Converter getConverter(
+      final FacesContext facesContext, final UIComponent component, final Object value) {
 
     Converter converter = null;
     if (component instanceof ValueHolder) {
@@ -831,7 +832,16 @@ public final class ComponentUtils {
     if (converter == null) {
       final ValueExpression valueExpression = component.getValueExpression("value");
       if (valueExpression != null) {
-        final Class converterType = valueExpression.getType(facesContext.getELContext());
+        Class converterType = null;
+        if (value != null) {
+          converterType = value.getClass();
+        } else {
+          try {
+            converterType = valueExpression.getType(facesContext.getELContext());
+          } catch (Exception e) {
+            // ignore, seems not to be possible, when EL is a funktion like #{bean.getName(item.id)}
+          }
+        }
         if (converterType != null && converterType != String.class && converterType != Object.class) {
           converter = facesContext.getApplication().createConverter(converterType);
         }
@@ -849,7 +859,7 @@ public final class ComponentUtils {
       return "";
     }
 
-    final Converter converter = ComponentUtils.getConverter(facesContext, component);
+    final Converter converter = ComponentUtils.getConverter(facesContext, component, currentValue);
     if (converter != null) {
       return converter.getAsString(facesContext, component, currentValue);
     } else {

Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/CurrentValueController.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/CurrentValueController.java?rev=1748568&r1=1748567&r2=1748568&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/CurrentValueController.java (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/CurrentValueController.java Wed Jun 15 12:15:45 2016
@@ -6,32 +6,60 @@ import org.slf4j.LoggerFactory;
 import javax.inject.Named;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Currency;
 import java.util.Date;
+import java.util.GregorianCalendar;
 
 @Named
 public class CurrentValueController {
 
   private static final Logger LOG = LoggerFactory.getLogger(CurrentValueController.class);
 
+  public String string;
   public Date date;
+  public Currency currency;
 
   public CurrentValueController() {
+
+    string = "simple string";
+
     try {
       this.date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("1969-07-24 16:50:35");
     } catch (ParseException e) {
       LOG.error("", e);
     }
+
+    currency = Currency.getInstance("TTD");
+  }
+
+  public String toUpperCase(final String text) {
+    return text != null ? text.toUpperCase() : null;
+  }
+
+  public Date plus50(final Date base) {
+    if (date == null) {
+      return null;
+    }
+    final GregorianCalendar calendar = new GregorianCalendar();
+    calendar.setTime(date);
+    calendar.add(Calendar.YEAR, 50);
+    return calendar.getTime();
+  }
+
+  public Currency toCurrency(String string) {
+    return Currency.getInstance(string);
   }
 
   public String getString() {
-    return "simple string";
+    return string;
   }
 
   public Date getDate() {
     return date;
   }
 
-  public String toUpperCase(final String text) {
-    return text != null ? text.toUpperCase() : null;
+  public Currency getCurrency() {
+    return currency;
   }
 }

Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/50000-java/10-rendererBase-getCurrentValue/rendererBase-getCurrentValue.test.js
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/50000-java/10-rendererBase-getCurrentValue/rendererBase-getCurrentValue.test.js?rev=1748568&r1=1748567&r2=1748568&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/50000-java/10-rendererBase-getCurrentValue/rendererBase-getCurrentValue.test.js (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/50000-java/10-rendererBase-getCurrentValue/rendererBase-getCurrentValue.test.js Wed Jun 15 12:15:45 2016
@@ -19,18 +19,31 @@ function jQueryFrame(expression) {
   return document.getElementById("page:testframe").contentWindow.jQuery(expression);
 }
 
+function test(assert, idSuffix, expectedText) {
+  var $out = jQueryFrame("#page\\:" + idSuffix);
+  assert.equal($out.text().trim(), expectedText);
+}
+
 QUnit.test("formatted values: out string", function (assert) {
-  var $out = jQueryFrame("#page\\:outString");
-  assert.equal($out.text().trim(), "simple string");
+  test(assert, "outString", "simple string");
+});
+
+QUnit.test("formatted values: out string from method", function (assert) {
+  test(assert, "outStringFromMethod", "HELLO WORLD!");
 });
 
 QUnit.test("formatted values: out date", function (assert) {
-  var $out = jQueryFrame("#page\\:outDate");
-  assert.equal($out.text().trim(), "24.07.1969");
+  test(assert, "outDate", "24.07.1969");
+});
+
+QUnit.test("formatted values: out date from method", function (assert) {
+  test(assert, "outDateFromMethod", "24.07.2019");
+});
+
+QUnit.test("formatted values: out currency", function (assert) {
+  test(assert, "outCurrency", "TTD");
 });
 
-// TODO: we may need not trim() below, if we have a labelLayout="skip" freature to skip the sourounging container.
-QUnit.test("formatted values: out method", function (assert) {
-  var $out = jQueryFrame("#page\\:outMethod");
-  assert.equal($out.text().trim(), "HELLO WORLD!");
+QUnit.test("formatted values: out currency from method", function (assert) {
+  test(assert, "outCurrencyFromMethod", "ISK");
 });

Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/50000-java/10-rendererBase-getCurrentValue/rendererBase-getCurrentValue.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/50000-java/10-rendererBase-getCurrentValue/rendererBase-getCurrentValue.xhtml?rev=1748568&r1=1748567&r2=1748568&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/50000-java/10-rendererBase-getCurrentValue/rendererBase-getCurrentValue.xhtml (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/50000-java/10-rendererBase-getCurrentValue/rendererBase-getCurrentValue.xhtml Wed Jun 15 12:15:45 2016
@@ -19,14 +19,20 @@
 
 <ui:composition template="/main.xhtml"
                 xmlns:tc="http://myfaces.apache.org/tobago/component"
-                xmlns:ui="http://java.sun.com/jsf/facelets">
+                xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html">
 
   <ui:param name="title" value="Test: RendererBase.getCurrentValue()"/>
 
   <tc:out id="outString" labelLayout="none" value="#{currentValueController.string}"/>
 
+  <tc:out id="outStringFromMethod" labelLayout="none" value="#{currentValueController.toUpperCase('Hello world!')}"/>
+
   <tc:out id="outDate" labelLayout="none" value="#{currentValueController.date}"/>
 
-  <tc:out id="outMethod" labelLayout="none" value="#{currentValueController.toUpperCase('Hello world!')}"/>
+  <tc:out id="outDateFromMethod" labelLayout="none" value="#{currentValueController.plus50(currentValueController.date)}"/>
+
+  <tc:out id="outCurrency" labelLayout="none" value="#{currentValueController.currency}"/>
+
+  <tc:out id="outCurrencyFromMethod" labelLayout="none" value="#{currentValueController.toCurrency('ISK')}"/>
 
 </ui:composition>

Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/test/java/org/apache/myfaces/tobago/example/demo/QUnitTests.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/test/java/org/apache/myfaces/tobago/example/demo/QUnitTests.java?rev=1748568&r1=1748567&r2=1748568&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/test/java/org/apache/myfaces/tobago/example/demo/QUnitTests.java (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/test/java/org/apache/myfaces/tobago/example/demo/QUnitTests.java Wed Jun 15 12:15:45 2016
@@ -106,7 +106,7 @@ public class QUnitTests {
 
   @Test
   public void allPages() {
-
+    LOG.warn("Not implemented yet!");
   }
 
   @Test
@@ -126,4 +126,10 @@ public class QUnitTests {
     String page = "content/40-test/1040-date/date.xhtml";
     checkResults(page);
   }
+
+  @Test
+  public void rendererBase_getCurrentValue() {
+    String page = "content/40-test/50000-java/10-rendererBase-getCurrentValue/rendererBase-getCurrentValue.xhtml";
+    checkResults(page);
+  }
 }