Frantisek Kossuth
Frantisek Kossuth

Reputation: 3524

Simplest URL encode/decode pattern for parameters used with datasources

Application uses mechanism for filtering documents in view by category - all available categories (just a few) are looked up and fed to Outline component. Each Outline entry then adds URL parameter used in view datasource to filter documents by category. Problem is with non ANSI characters (international). In many cases it is working as expected, but some proxies forbid to use these characters in URL.

The workaround is to use encode/decode of url, what makes alight complication to SSJS code in Category property of view datasource: instead of simple context.getUrlParameter("category"); there is need to decode parameters, which is "complicated", for example this way: http://www.mkyong.com/java/how-to-encode-a-url-string-or-form-parameter-in-java/

Is there any XPages specific way to simplify this?

Upvotes: 2

Views: 3497

Answers (1)

Sven Hasselbach
Sven Hasselbach

Reputation: 10485

Non-ANSI characters are not allowed in older RFC specifications and have to be encoded. There are SSJS functions named escape and unescape, but they are not working correctly (last tested with 8.5.3)

But you can use the Java instead. Before adding a parameter to the URL, you can use this SSJS:

java.net.URLEncoder.encode (" ABC DEF", "utf-8")

This will give you a result of %20ABC%20DEF and can be added to your URL as a parameter (f.e. ?category=%20ABC%20DEF).

To decode the parameter in SSJS, you can revert it by using

var hlp = context.getUrlParameter("category");
var param = java.net.URLDecoder.decode (hlp, "utf-8")

Upvotes: 13

Related Questions