hi,

this patch adds support for javascript: urls in display:table's
requestURI attribute. the string {} is replaced by properly quoted
displaytag-generated url query parameters. example:

<script type="text/javascript">
        function Invoke(parm)
        {
                ...
                window.location = "?" + parm + "&...=" + ...;
        }
</script>
...
<display:table ... requestURI="javascript:Invoke({})" ...>
...

the error handling in DefaultHref is a gross hack, but i leave it up to
you to do something useful to it. :)

-- 
Hi! I'm a .signature virus! Copy me into your ~/.signature, please!
--
Chaos, panic, and disorder - my work here is done.
Index: main/java/org/displaytag/util/DefaultHref.java
===================================================================
--- main/java/org/displaytag/util/DefaultHref.java      (revision 1088)
+++ main/java/org/displaytag/util/DefaultHref.java      (working copy)
@@ -11,6 +11,8 @@
  */
 package org.displaytag.util;
 
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -67,8 +69,15 @@
      */
     public void setFullUrl(String baseUrl)
     {
+        this.anchor = null;
+
+        if (baseUrl.startsWith("javascript:"))
+        {
+            this.url = baseUrl;
+            return;
+        }
+
         this.url = null;
-        this.anchor = null;
         String noAnchorUrl;
         int anchorposition = baseUrl.indexOf('#');
 
@@ -296,11 +305,19 @@
     {
         StringBuffer buffer = new StringBuffer(30);
 
-        buffer.append(this.url);
+        boolean jsUrl = url.startsWith("javascript:");
 
+        if (!jsUrl)
+        {
+            buffer.append(this.url);
+        }
+
         if (this.parameters.size() > 0)
         {
-            buffer.append('?');
+            if (!jsUrl)
+            {
+                buffer.append('?');
+            }
             Set parameterSet = this.parameters.entrySet();
 
             Iterator iterator = parameterSet.iterator();
@@ -341,6 +358,24 @@
             }
         }
 
+        if (jsUrl)
+        {
+            int xoff = this.url.indexOf("{}", 11); // skip "javascript:"
+            if (xoff < 0)
+            {
+                return "javascript:alert('displayTag: fix requestURI!')";
+            }
+            try
+            {
+                // assuming the rest of the URL to be already encoded - 
otherwise we wouldn't have been able to put it in requestURI
+                return this.url.substring(0, xoff) + '\'' + 
URLEncoder.encode(buffer.toString(), "UTF-8") + '\'' + this.url.substring(xoff 
+ 2);
+            }
+            catch (UnsupportedEncodingException e)
+            {
+                throw new RuntimeException(e);
+            }
+        }
+
         if (this.anchor != null)
         {
             buffer.append('#');
Index: main/java/org/displaytag/tags/TableTag.java
===================================================================
--- main/java/org/displaytag/tags/TableTag.java (revision 1088)
+++ main/java/org/displaytag/tags/TableTag.java (working copy)
@@ -1098,24 +1128,27 @@
         {
             // if user has added a requestURI create a new href
             String fullURI = requestUri;
-            if (!this.dontAppendContext)
+            if (!fullURI.startsWith("javascript:"))
             {
-                String contextPath = ((HttpServletRequest) 
this.pageContext.getRequest()).getContextPath();
+                if (!this.dontAppendContext)
+                {
+                    String contextPath = ((HttpServletRequest) 
this.pageContext.getRequest()).getContextPath();
 
-                // prepend the context path if any.
-                // actually checks if context path is already there for people 
which manually add it
-                if (!StringUtils.isEmpty(contextPath)
-                    && requestUri != null
-                    && requestUri.startsWith("/")
-                    && !requestUri.startsWith(contextPath))
-                {
-                    fullURI = contextPath + this.requestUri;
+                    // prepend the context path if any.
+                    // actually checks if context path is already there for 
people which manually add it
+                    if (!StringUtils.isEmpty(contextPath)
+                        && requestUri != null
+                        && requestUri.startsWith("/")
+                        && !requestUri.startsWith(contextPath))
+                    {
+                        fullURI = contextPath + this.requestUri;
+                    }
                 }
+
+                // call encodeURL to preserve session id when cookies are 
disabled
+                fullURI = ((HttpServletResponse) 
this.pageContext.getResponse()).encodeURL(fullURI);
             }
 
-            // call encodeURL to preserve session id when cookies are disabled
-            fullURI = ((HttpServletResponse) 
this.pageContext.getResponse()).encodeURL(fullURI);
-
             baseHref.setFullUrl(fullURI);
 
             // // ... and copy parameters from the current request
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
displaytag-devel mailing list
displaytag-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/displaytag-devel

Reply via email to