Bill F
Bill F

Reputation: 2087

Using encodeURIComponent in XPages

In the W3Schools they give this example:

var uri = "http://w3schools.com/my test.asp?name=ståle&car=saab";
var res = encodeURIComponent(uri);

Which does what I want however, when I run it I get an error that encodeURIComponent is not implemented.

try{    
    var str:String = "Contracts and Leases";
    var rtn = encodeURIComponent(str);
}catch(e){
    println(e)
}

added the above to a button i get the not implemented error. Is there an equivalent I just need to replace the spaces with %20s.

Upvotes: 1

Views: 497

Answers (1)

Per Henrik Lausten
Per Henrik Lausten

Reputation: 21709

Use java.net.URLEncoder.encode(stringToEncode, "utf-8") so in your case do this:

try{    
    var str:String = "Contracts and Leases";
    var rtn = java.net.URLEncoder.encode(str, "utf-8");
}catch(e){
    println(e)
}

Upvotes: 8

Related Questions