openlayers/openlayers — pull request #968 by bartvde (2014-07-17 09:31:22+00:00)
Title: No support for viewParams in WFS protocols 

Summary
-----------------

[Geoserver recently gained support](http://jira.codehaus.org/browse/GEOS-5160) for the viewParams parameter in WFS requests. However, currently Openlayers has no facility to pass these requests on. So this ticket is for adding viewparams support (which is really simple btw).

Functionality
------------------
Openlayers passing viewparams values across to the WFS server for WFS requests.

Interdependencies
--------------------------
viewparams is a Geoserver vendor extension, so it's use is really dependant on Geoserver being the back end. However I can't imagine, given the implementation, it breaking interoperability with other implementations.

Changes to API
-----------------------
All WFS requests would need to take a viewParams parameter. This could be passed in the options object and would therefore only require something like the following in the inline documentation:

* viewParams - {String} Geoserver vendor extension parameters that will be
* added to the request

(in my version this is at line 117 of lib/OpenLayers/Protocol/WFS/v1.js)

Suggested strategies
-------------------------------
I recommend simply adding the option to the documentation and passing the parameter through in the format object where the element is created. So where the code is:

var node = this.createElementNSPlus("wfs:GetFeature", {
attributes: {
service: "WFS",
version: this.version,
handle: options && options.handle,
outputFormat: options && options.outputFormat,
maxFeatures: options && options.maxFeatures,
"xsi:schemaLocation": this.schemaLocationAttr(options)
}

a line could be inserted to the attributes being:

viewParams: options && options.viewParams,

(I've got this at line 232 in lib/OpenLayers/Format/WFST/v1.js in my version)

Alternatives
----------------
I'm not aware of any alternative mechanism of supplying vendor viewparams to Geoserver, nor any other reasonable way of implementing it relative to how OpenLayers is written

Side-effects/Complications
--------------------------------------
Probably the most significant side-effect of this is that someone could pass a viewParams parameter to a non-geoserver back end. However given it adds an attribute to the XML, and given the generally extensible nature of XML, it's likely that only the most strict of parsers would pick this up as an error (eg. if all requests were validated against a DTD).

Since it is the users choice to include this parameter, though, and they would be doing it knowing it's a vendor extension specific to Geoserver; this would be unlikely in reality to cause any issues.

Note
------
Please note that I based the above suggested changes on commit 5b98769234dc20172a3cb6eeb77e60b297766e45, which was a while ago. If a more up-to-date recommendation is needed, I'm happy to grab the latest version and locate the appropriate parts of the code matching the above changes.