From: <jt...@hy...> - 2007-06-07 20:39:05
|
Author: jtravis Date: 2007-06-07 13:39:02 -0700 (Thu, 07 Jun 2007) New Revision: 4696 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=4696 Modified: trunk/src/org/hyperic/hq/hqu/rendit_sys/html/HtmlUtil.groovy Log: Add query param support to urlFor Modified: trunk/src/org/hyperic/hq/hqu/rendit_sys/html/HtmlUtil.groovy =================================================================== --- trunk/src/org/hyperic/hq/hqu/rendit_sys/html/HtmlUtil.groovy 2007-06-07 19:56:33 UTC (rev 4695) +++ trunk/src/org/hyperic/hq/hqu/rendit_sys/html/HtmlUtil.groovy 2007-06-07 20:39:02 UTC (rev 4696) @@ -13,21 +13,33 @@ * action: The target action within the current controller to execute * id: Either an integer, or an object which answers to .getId(), which * will pass an id= query parameter - * - * TODO: Add support for arbitrary URL query params + * + * Any additional values in the map will be passed as query parameters */ static String urlFor(opts) { + opts = new HashMap(opts) def res = '' + def qparams = [:] if (opts['action']) { - res += opts['action'] + '.hqu' + res += opts['action'] + '.hqu' + opts.remove('action') } if (opts['id'] != null) { def id = opts['id'] if (!(id instanceof Number)) id = id.id // Call 'getId' on the object if it's not a number - res += "?id=$id" + qparams['id'] = "${id}" + opts.remove('id') } + + def addedParam = false + for (o in opts) { + if (!addedParam) + res += '?' + res += "${o.key}=${escapeHtml(o.value)}&" + addedParam = true + } res } |