You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-dev@jakarta.apache.org by lu...@apache.org on 2002/01/11 23:38:17 UTC
cvs commit: jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt FormatDateSupport.java FormatNumberSupport.java
luehe 02/01/11 14:38:17
Modified: standard/src/org/apache/taglibs/standard/tag/common/fmt
FormatDateSupport.java FormatNumberSupport.java
Log:
<fmt:formatNumber>
Problem:
-------
<fmt:formatNumber value="$books.rows[0].columns[4]" type="currency"/>
throws exception, since supplied value is instance of Column, but
<fmt:formatNumber> requires it to be a String or Number.
Workaround:
----------
If 'value' is neither a Number nor a String, it is converted to a
String.
Note:
----
It seems like we need to add methods to the Row interface that
will return the column "value" as opposed to an instance of "Column".
Otherwise, any tag that requires a special input type will not be able
to process the result of a database lookup.
In the case of <fmt:formatNumber>, this is not such a big deal, as
this action already accepts String objects (in addition to instances
of java.lang.Number), but this may not be true for other tags.
We will raise this issue with the expert group.
(Similar workaround implemented for <fmt:formatDate>.)
Revision Changes Path
1.7 +11 -0 jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/FormatDateSupport.java
Index: FormatDateSupport.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/FormatDateSupport.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- FormatDateSupport.java 9 Jan 2002 19:51:47 -0000 1.6
+++ FormatDateSupport.java 11 Jan 2002 22:38:17 -0000 1.7
@@ -168,6 +168,17 @@
public int doEndTag() throws JspException {
/*
+ * If 'value' is neither a Number nor a Date, it is converted to a
+ * String. For example, this is necessary if 'value' is the result
+ * of a database lookup, in which case it will be an instance of
+ * org.apache.taglibs.standard.tag.common.sql.ColumnImpl.
+ */
+ if ((value != null)
+ && !(value instanceof Date) && !(value instanceof String)) {
+ value = value.toString();
+ }
+
+ /*
* If no date or time is given, the current date and time are used.
* If the date and/or time is given as a string literal, it is first
* parsed into an instance of java.util.Date according to the default
1.6 +14 -4 jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/FormatNumberSupport.java
Index: FormatNumberSupport.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/FormatNumberSupport.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- FormatNumberSupport.java 18 Dec 2001 01:53:15 -0000 1.5
+++ FormatNumberSupport.java 11 Jan 2002 22:38:17 -0000 1.6
@@ -152,10 +152,20 @@
}
/*
- * If the value given is a string literal, it is first parsed into an
- * instance of java.lang.Number according to the default pattern of
- * the locale given via the 'parseLocale' attribute. If this attribute
- * is missing, the default ("en") locale is used.
+ * If 'value' is neither a Number nor a String, it is converted to a
+ * String. For example, this is necessary if 'value' is the result
+ * of a database lookup, in which case it will be an instance of
+ * org.apache.taglibs.standard.tag.common.sql.ColumnImpl.
+ */
+ if (!(value instanceof Number) && !(value instanceof String)) {
+ value = value.toString();
+ }
+
+ /*
+ * If 'value' is a String, it is first parsed into an instance of
+ * java.lang.Number according to the default pattern of the locale
+ * given via the 'parseLocale' attribute. If this attribute is missing,
+ * the default ("en") locale is used.
*/
if (value instanceof String) {
NumberFormat parser = null;
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>