In a Tapestry-generated web page I have some Javascript like this:

                var arg = 'StringWithoutSpaces'; // Works only if no spaces in 
this string.

                var sLink = '/mypage.mycomponent:myevent/' + 
encodeURIComponent(arg);

                alert(sLink); // Just for debug.

                location.href = sLink;

This works as I expected, that is in the Java class of the component the method

                onMyEvent(String arg)

gets called and it receives the value "StringWithoutSpaces" in arg.

The problem is that if the argument contains spaces (ASCII 32), for ex.

                var arg = 'String With Spaces';

then I get the below exception.

I don't understand why, because from the Javascript alert box I can see that 
the spaces were correctly encoded into %20, so when the browser executes the 
Javascript statement

                location.href = sLink;

the variable sLink has a value without any actual space:

/mypage.mycomponent:myevent/String%20With%20Spaces

So I'm wondering what is the right way to pass spaces - and possibly other 
characters that might have the same problem as the space. I thought a right way 
was to escape them with encodeURIComponent() in the Javascript that makes the 
call, but it looks like it's not right.

The exception is:

java.lang.IllegalArgumentException
Input string 'String With Spaces' is not valid; the character ' ' at position 7 
is not valid.

Stack trace
org.apache.tapestry5.internal.services.URLEncoderImpl.decode(URLEncoderImpl.java:144)
org.apache.tapestry5.internal.services.ContextPathEncoderImpl.decodePath(ContextPathEncoderImpl.java:92)
org.apache.tapestry5.internal.services.ComponentEventLinkEncoderImpl.validateAndConstructComponentEventRequest(ComponentEventLinkEncoderImpl.java:377)
org.apache.tapestry5.internal.services.ComponentEventLinkEncoderImpl.decodeComponentEventRequest(ComponentEventLinkEncoderImpl.java:329)
org.apache.tapestry5.internal.services.linktransform.LinkTransformerInterceptor.decodeComponentEventRequest(LinkTransformerInterceptor.java:58)
org.apache.tapestry5.internal.services.ComponentEventDispatcher.dispatch(ComponentEventDispatcher.java:42)
org.apache.tapestry5.services.TapestryModule$RequestHandlerTerminator.service(TapestryModule.java:302)
org.apache.tapestry5.internal.services.RequestErrorFilter.service(RequestErrorFilter.java:26)
org.apache.tapestry5.services.TapestryModule$3.service(TapestryModule.java:902)
org.apache.tapestry5.services.TapestryModule$2.service(TapestryModule.java:892)
org.apache.tapestry5.internal.services.StaticFilesFilter.service(StaticFilesFilter.java:90)
...
...

Reply via email to