dev@javaserverfaces.java.net

[Fwd: [REVIEW] Update convertDateTime locale and timeZone attributes to accept Object]

From: Ryan Lubke <Ryan.Lubke_at_Sun.COM>
Date: Mon, 23 May 2005 09:51:48 -0400

This is an updated version of the previous change bundle.
Added error case for when the attribute doesn't resolve to a
String, Locale, or TimeZone instance.

SECTION: Modified Files
----------------------------
M conf/share/jsf_core.tld
  - update convertDateTime locale and timeZone attributes to accept Object.

M src/com/sun/faces/taglib/jsf_core/ConvertDateTimeTag.java
  - updated setPropertiesLogic to take the above info into account.

M src/com/sun/faces/util/Util.java
M src/com/sun/faces/LogStrings.properties
M src/javax/faces/Messages.properties
  - added new messages

M systest/build-tests.xml
  - added new systest converter05

M test/com/sun/faces/util/TestUtil_messages.java
  - added new message to test

A systest/web/converter05.jsp
A systest/web/golden/standard/converter05.txt
  - new systest to ensure the locale and timeZone attributes
   accept:
     * literal text
     * VE resolving to a String
     * VE resolving to either a Locale or TimeZone object depending
        on attribute

SECTION: Diffs
----------------------------
Index: conf/share/jsf_core.tld
===================================================================
RCS file: /cvs/javaserverfaces-sources/jsf-ri/conf/share/jsf_core.tld,v
retrieving revision 1.52
diff -u -r1.52 jsf_core.tld
--- conf/share/jsf_core.tld 20 May 2005 16:10:25 -0000 1.52
+++ conf/share/jsf_core.tld 23 May 2005 13:59:58 -0000
@@ -168,7 +168,7 @@
             <name>locale</name>
             <required>false</required>
             <deferred-value>
- <type>java.util.Locale</type>
+ <type>java.lang.Object</type>
             </deferred-value>
         </attribute>
 
@@ -207,7 +207,7 @@
             </description>
             <name>timeZone</name>
             <deferred-value>
- <type>java.util.TimeZone</type>
+ <type>java.lang.Object</type>
             </deferred-value>
         </attribute>
 
Index: src/com/sun/faces/LogStrings.properties
===================================================================
RCS file:
/cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/LogStrings.properties,v
retrieving revision 1.1
diff -u -r1.1 LogStrings.properties
--- src/com/sun/faces/LogStrings.properties 5 Apr 2005 20:25:12
-0000 1.1
+++ src/com/sun/faces/LogStrings.properties 23 May 2005 13:59:59 -0000
@@ -46,3 +46,6 @@
 jsf.redirect_failed_error=JSF1008: Redirect to path {0} failed
 jsf.faces_servlet_mapping_cannot_be_determined_error=JSF1009: Unable to
determine FaceServlet mapping for servlet path {0}.
 jsf.illegal_view_id_error=JSF1010: Illegal view ID {0}. The ID must
begin with ''/''
+
+# core tags
+jsf.core.tags.eval_result_not_expected_type=JSF1011: Evaluation of
expression for attribute ''{0}'' resulted in unexpected type. Expected
{1}, but received {2}.
Index: src/com/sun/faces/taglib/jsf_core/ConvertDateTimeTag.java
===================================================================
RCS file:
/cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/taglib/jsf_core/ConvertDateTimeTag.java,v
retrieving revision 1.16
diff -u -r1.16 ConvertDateTimeTag.java
--- src/com/sun/faces/taglib/jsf_core/ConvertDateTimeTag.java 19 May
2005 13:26:59 -0000 1.16
+++ src/com/sun/faces/taglib/jsf_core/ConvertDateTimeTag.java 23 May
2005 13:59:59 -0000
@@ -11,6 +11,8 @@
 
 import java.util.Locale;
 import java.util.TimeZone;
+import java.util.logging.Logger;
+import java.util.logging.Level;
 
 import javax.el.ELContext;
 import javax.el.ValueExpression;
@@ -18,6 +20,7 @@
 import javax.faces.context.FacesContext;
 import javax.faces.convert.Converter;
 import javax.faces.convert.DateTimeConverter;
+import javax.faces.FacesException;
 import javax.servlet.jsp.JspException;
 
 import com.sun.faces.util.Util;
@@ -34,6 +37,9 @@
 
     private static final long serialVersionUID = -5815655767093677438L;
     private static ValueExpression CONVERTER_ID_EXPR = null;
+ // Log instance for this class
+ private static final Logger logger = Util.getLogger(Util.FACES_LOGGER);
+
 
     //
     // Instance Variables
@@ -195,11 +201,28 @@
                 locale =
                 new Locale(localeExpression.getExpressionString(), "");
             } else {
- Locale loc = (Locale)
- Util.evaluateValueExpression(localeExpression,
+ Object loc = Util.evaluateValueExpression(localeExpression,
                     elContext);
                 if (loc != null) {
- locale = loc;
+ if (loc instanceof String) {
+ locale = new Locale((String) loc, "");
+ } else if (loc instanceof Locale) {
+ locale = (Locale) loc;
+ } else {
+ Object[] params = {
+ "locale",
+ "java.lang.String or java.util.Locale",
+ loc.getClass().getName()
+ };
+ if (logger.isLoggable(Level.SEVERE)) {
+ logger.log(Level.SEVERE,
+
"jsf.core.tags.eval_result_not_expected_type",
+ params);
+ }
+ throw new FacesException(
+ Util.getExceptionMessageString(
+ Util.EVAL_ATTR_UNEXPECTED_TYPE, params));
+ }
                 } else {
                     locale = facesContext.getViewRoot().getLocale();
                 }
@@ -211,9 +234,29 @@
                 TimeZone.getTimeZone(
                     timeZoneExpression.getExpressionString());
             } else {
- timeZone = (TimeZone)
- Util.evaluateValueExpression(timeZoneExpression,
+ Object tz =
Util.evaluateValueExpression(timeZoneExpression,
                     elContext);
+ if (tz != null) {
+ if (tz instanceof String) {
+ timeZone = TimeZone.getTimeZone((String) tz);
+ } else if (tz instanceof TimeZone) {
+ timeZone = (TimeZone) tz;
+ } else {
+ Object[] params = {
+ "timeZone",
+ "java.lang.String or java.util.TimeZone",
+ tz.getClass().getName()
+ };
+ if (logger.isLoggable(Level.SEVERE)) {
+ logger.log(Level.SEVERE,
+
"jsf.core.tags.eval_result_not_expected_type",
+ params);
+ }
+ throw new FacesException(
+ Util.getExceptionMessageString(
+ Util.EVAL_ATTR_UNEXPECTED_TYPE,
params));
+ }
+ }
             }
         }
     }
Index: src/com/sun/faces/util/Util.java
===================================================================
RCS file:
/cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/util/Util.java,v
retrieving revision 1.160
diff -u -r1.160 Util.java
--- src/com/sun/faces/util/Util.java 18 May 2005 17:34:08 -0000 1.160
+++ src/com/sun/faces/util/Util.java 23 May 2005 14:00:00 -0000
@@ -333,6 +333,9 @@
             "com.sun.faces.PROPERTY_TYPE_ERROR";
     public static final String EL_SIZE_OUT_OF_BOUNDS_ERROR_ID =
             "com.sun.faces.SIZE_OUT_OF_BOUNDS_ERROR";
+
+ public static final String EVAL_ATTR_UNEXPECTED_TYPE =
+ "com.sun.faces.EVAL_ATTR_UNEXPECTED_TYPE";
     
 // README - make sure to add the message identifier constant
 // (ex: Util.CONVERSION_ERROR_MESSAGE_ID) and the number of substitution
Index: src/javax/faces/Messages.properties
===================================================================
RCS file:
/cvs/javaserverfaces-sources/jsf-ri/src/javax/faces/Messages.properties,v
retrieving revision 1.28
diff -u -r1.28 Messages.properties
--- src/javax/faces/Messages.properties 18 May 2005 17:34:09 -0000
 1.28
+++ src/javax/faces/Messages.properties 23 May 2005 14:00:01 -0000
@@ -135,6 +135,7 @@
 com.sun.faces.ERROR_OPENING_FILE=Can''t open configuration file: ''{0}''.
 com.sun.faces.ERROR_REGISTERING_DTD=Can''t register DTD: ''{0}''.
 com.sun.faces.ERROR_SETTING_BEAN_PROPERTY=Can''t set managed bean
property: ''{0}''.
+com.sun.faces.EVAL_ATTR_UNEXPECTED_TYPE=Evaluation of expression for
attribute ''{0}'' resulted in unexpected type. Expected {1}, but
received {2}.
 com.sun.faces.FACES_CONTEXT_CONSTRUCTION_ERROR=Construction Error: One
or more input parameters may be null.
 com.sun.faces.FACES_SERVLET_MAPPING_CANNOT_BE_DETERMINED=Unable to
determine FaceServlet mapping for servlet path ''{0}''.
 com.sun.faces.FILE_NOT_FOUND=File Not Found for file: ''{0}''.
Index: systest/build-tests.xml
===================================================================
RCS file: /cvs/javaserverfaces-sources/jsf-ri/systest/build-tests.xml,v
retrieving revision 1.78
diff -u -r1.78 build-tests.xml
--- systest/build-tests.xml 21 May 2005 00:01:04 -0000 1.78
+++ systest/build-tests.xml 23 May 2005 14:00:02 -0000
@@ -86,6 +86,7 @@
                 test.converter02,
                 test.converter03,
                 test.converter04,
+ test.converter05,
                 test.validator,
                 test.validator01,
                 test.validator02,
@@ -546,7 +547,14 @@
          status="200" failonerror="${failonerror}"/>
   </target>
 
- <target name="test.validator"
+ <target name="test.converter05">
+ <tester host="${host}" port="${port}" protocol="${protocol}"
+ request="${context.path}/faces/converter05.jsp"
+ recordGolden="${local.golden.path}/standard/converter05.txt"
+ golden="${golden.path}/standard/converter05.txt"
failonerror="${failonerror}"/>
+ </target>
+
+ <target name="test.validator"
    description="Test Validator creation facility">
 
     <!-- Test validator creation -->
Index: test/com/sun/faces/util/TestUtil_messages.java
===================================================================
RCS file:
/cvs/javaserverfaces-sources/jsf-ri/test/com/sun/faces/util/TestUtil_messages.java,v
retrieving revision 1.41
diff -u -r1.41 TestUtil_messages.java
--- test/com/sun/faces/util/TestUtil_messages.java 18 May 2005
17:35:20 -0000 1.41
+++ test/com/sun/faces/util/TestUtil_messages.java 23 May 2005
14:00:05 -0000
@@ -122,7 +122,8 @@
         {Util.INCORRECT_JSP_VERSION_ID, "1"},
         {Util.EL_OUT_OF_BOUNDS_ERROR_ID, "1"},
         {Util.EL_PROPERTY_TYPE_ERROR_ID, "1"},
- {Util.EL_SIZE_OUT_OF_BOUNDS_ERROR_ID,"2"}
+ {Util.EL_SIZE_OUT_OF_BOUNDS_ERROR_ID,"2"},
+ {Util.EVAL_ATTR_UNEXPECTED_TYPE, "3"}
     };
 
     private String[][] toolsMessageInfo = {


SECTION: New Files
----------------------------
SEE ATTACHMENTS