4

I am trying to zoom plot numbers.Plot numbers like 1 10-12 13/P road 20(A) 100&102 and etc.I am able to zoom to all combination plot numbers except 1,2,3.when I pass such value its trowing error:

1 feature types requested, but found 2 view params specified

geoserver sql view is:

select * from plotboundary where nmindar='%nmindar%' and plno='%plno%'

default values and validation are

Name  | Default Value   | validation

nmidar| Hanagawadi I A  | ^[\w\d\s]+$

plno  |  100,102&103    | ^[ A-Za-z0-9_ *@.\/#&+-\,()-_]*$

ajax function:

 $.ajax({
            url: 'http://XX.168.1.XX:8089/geoserver/XX/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=XX:vwplot&maxFeatures=5000&outputFormat=text/javascript',
            contentType: 'application/json',
            dataType: 'jsonp',
            jsonpCallback: "parseResponse",
            data: {
                viewparams: "nmindar:" + nmindar + ";plno:" + plno
            }

Can any one tell me how to pass value to viewparams in geoserver, value includes comma. For example as mentioned above "100,102&103" is a single value(plot number).Here comma is not a separator.

4

After looking at the Geoserver docs, I realized that we need to escape all the commas and semicolons.

The Geoserver docs for SQL Views says:

If the values contain semicolons or commas these must be escaped with a backslash (e.g. \, and \;).

We can do this using the following JavaScript code:

//Function to add replaceAll to Strings
String.prototype.replaceAll = function(search, replacement) {
    var target = this;
    return target.replace(new RegExp(search, 'g'), replacement);
};

function EscapeCommasSemiColons(input){
    var output=input.replaceAll(",", "\\,"); //replace all the commas
    output=output.replaceAll(";", "\\;"); //replace all the SemiColons
    return output;
}

//Now call the data from GeoServer

$.ajax({
        url: 'http://XX.168.1.XX:8089/geoserver/XX/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=XX:vwplot&maxFeatures=5000&outputFormat=text/javascript',
        contentType: 'application/json',
        dataType: 'jsonp',
        jsonpCallback: "parseResponse",
        data: {
            viewparams: "nmindar:" + nmindar + ";plno:" + EscapeCommasSemiColons(plno)
        }});
  • for your suggestion i am getting only default values – veena hosur Jul 16 '16 at 6:44
  • No,its single plot number. See my updated question – veena hosur Jul 16 '16 at 7:32
  • its not working.I have checked my regex, for that value regex is correct – veena hosur Jul 16 '16 at 7:43
  • 1
    @veenahosur; I've updated the answer after reading the docs and testing the solution. Please check if this work for you. – Devdatta Tengshe Jul 16 '16 at 9:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.