Revision: 559
http://svn.sourceforge.net/stripes/?rev=559&view=rev
Author: bengunter
Date: 2007-05-28 20:57:53 -0700 (Mon, 28 May 2007)
Log Message:
-----------
Resolved (again) STS-374: stripes:param should use formatters when possible.
Resolved STS-322: Use formatting framework within <s:param> and
Resolution.addParameter().
LinkTagSupport.buildUrl() now formats all the values in the parameter map using
null for both format type and format pattern. This affects both s:link and
s:url.
Modified Paths:
--------------
trunk/stripes/src/net/sourceforge/stripes/tag/LinkTagSupport.java
Modified: trunk/stripes/src/net/sourceforge/stripes/tag/LinkTagSupport.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/tag/LinkTagSupport.java
2007-05-27 04:07:57 UTC (rev 558)
+++ trunk/stripes/src/net/sourceforge/stripes/tag/LinkTagSupport.java
2007-05-29 03:57:53 UTC (rev 559)
@@ -14,15 +14,20 @@
*/
package net.sourceforge.stripes.tag;
-import net.sourceforge.stripes.exception.StripesJspException;
-import net.sourceforge.stripes.util.UrlBuilder;
-import net.sourceforge.stripes.controller.StripesConstants;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import java.util.Map;
-import java.util.HashMap;
+import net.sourceforge.stripes.controller.StripesConstants;
+import net.sourceforge.stripes.controller.StripesFilter;
+import net.sourceforge.stripes.exception.StripesJspException;
+import net.sourceforge.stripes.format.Formatter;
+import net.sourceforge.stripes.format.FormatterFactory;
+import net.sourceforge.stripes.util.UrlBuilder;
+
/**
* Abstract support class for generating links. Used by both the LinkTag
(which generates
* regular [EMAIL PROTECTED] <a href=""/>} style links) and the UrlTag which
is a rough similie
@@ -171,8 +176,38 @@
if (addSourcePage) {
builder.addParameter(StripesConstants.URL_KEY_SOURCE_PAGE,
request.getServletPath());
}
- builder.addParameters(this.parameters);
+ // format parameters before appending to URL
+ Map<String, Object> parameters = new HashMap<String,
Object>(this.parameters);
+ for (Entry<String, Object> entry : parameters.entrySet()) {
+ entry.setValue(format(entry.getValue()));
+ }
+ builder.addParameters(parameters);
+
return response.encodeURL(builder.toString());
}
+
+ /**
+ * Attempts to format an object using an appropriate [EMAIL PROTECTED]
Formatter}. If
+ * no formatter is available for the object, then this method will call
+ * <code>toString()</code> on the object. A null <code>value</code> will
+ * be formatted as an empty string.
+ *
+ * @param value
+ * the object to be formatted
+ * @return the formatted value
+ */
+ @SuppressWarnings("unchecked")
+ protected String format(Object value) {
+ if (value == null)
+ return "";
+
+ FormatterFactory factory =
StripesFilter.getConfiguration().getFormatterFactory();
+ Formatter formatter = factory.getFormatter(value.getClass(),
+ getPageContext().getRequest().getLocale(), null, null);
+ if (formatter == null)
+ return String.valueOf(value);
+ else
+ return formatter.format(value);
+ }
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development