Question

How do you deal with the fact, that URLs are case sensitive in xPages even for parameters? For example URL:

my_page.xsp?folderid=785478 ... is not the same as ...
my_page.xsp?FOLDERID=785478

How to make, for example, a proper check that params contain some key e.g. param.containsKey("folderid") which desnt work when there is 'FOLDERID' in URL.

Was it helpful?

Solution

you may use this function:

context.getUrlParameter('param_name')

then test if it's null or not.

OTHER TIPS

I'd suggest defining a couple convenience @Functions:

var @HasParam = function(parameter) {
 var result:boolean = false;
 for (var eachParam : param.keySet()) {
  if (eachParam.toLowerCase() == parameter.toLowerCase()) {
   result = true;
   break;
  }
 }
 return result;
};

var @GetParam = function(parameter) {
 var result = "";
 if (@HasParam(parameter)) {
  for (var eachParam : param.keySet()) {
   if (eachParam.toLowerCase() == parameter.toLowerCase()) {
    result = param.get(eachParam);
    break;
   }   
  }
 }
 return result;
};

Then you can safely query the parameters without caring about case. For bonus points, you could add requestScope caching so that you can skip looping through the keySet if you're examining a parameter that you've previously looked at during the same request.

make sure to decide for one,so either upper or lowercase other than that i'd suggest something like

KeyValuePair<string,string> kvp = null;
foreach(KeyValuePair<string,string> p in param)
{
if(UPPERCASE(p.Key) == UPPERCASE("folderid"))
{
kvp = p;
break;
}
}

syntax isn't correct and idk the uppercase method in c# right now,but you get the point

The easiest answer is ofcourse the obvious. Be sure that the parameters you are using througout your application are always the same on every url you are generating and know what to expect. A good approach to accomplish this is to create a ssjs function which generates url's for you according to the objects you submit.

In this function you could check which object you are receiving and with the use of keywords and so forth generate the correct url. This way generating twice a url with the same input parameters should always generate the exact same url.

another option would be just to double check with a bit of code like this

var key = "yourkey";

if(param.contains(@uppercase(key)) || param.contains(@lowercase(key)){
 // do stuff
}

But should not be necesarry if the url you are parsing is generated by your own application


Edit after post of topic starter

Another option would be to grap the url directly from from the facescontext and to convert it to a string first. When it is a string you can parse the parameters yourself.

You can combine server side substitution/redirection to get around the issue that David mentioned. So a substitution rule will redirect incoming patern like this:

http://myhost/mypage/param (/mypage/* => which converts to - /dbpath/mypage.xsp?*) - substitution is tricky so please handle with care.

Also I believe I read somewhere that context.getUrlParameter is not case sensitive - can someone please confirm this.

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top