I know this is going to sound a bit weird, but here is the case... I have a JSF form which in the bottom load an "image viewer", implemented purely with javascript:
...
<p:fieldset legend="Viewer">
<p:outputPanel layout="block" styleClass="imageEditorImagePanel" />
</p:fieldset>
...
and the javascript code to load the image editor (OpenLayers):
...
function setImageEditorHeight(){
imageEditorID = $(".imageEditorImagePanel")[0].id;
....
}
...
function initialiseMap(){
...
map = new OpenLayers.Map(imageEditorID, options);
...
imageLayer = new OpenLayers.Layer.TMS(imgURL, "", {
url : '',
serviceVersion : '.',
layername : '.',
alpha : true,
type : 'png',
getURL : overlay_getTileURL,
transitionEffect: 'resize'
});
map.addLayer(imageLayer);
var vlayer = new OpenLayers.Layer.Vector("Editable");
map.addLayer(vlayer);
//add controls for drawing shaped on the map like:
var drawPointControl = new OpenLayers.Control.DrawFeatureOpt(vlayer, OpenLayers.Handler.Point,
{title:'Draw a point', text: 'Point','displayClass':'olControlDrawFeaturePoint'});
...
//add a save button to store shapes as geoJSON object
var save = new OpenLayers.Control.Button({
title: 'Save', text: 'Save',
trigger: function(){
var GEOJSON_PARSER = new OpenLayers.Format.GeoJSON();
var vectorLayerAsJson = GEOJSON_PARSER.write(vlayer.features);
alert(vectorLayerAsJson);
//i want something similar
//just for demonstrating, instead of URL i would like a way to post JSON object to bean
jQuery.ajax({
type: 'POST',
url: '/ajax/add',
dataType: 'json',
data: {"vLayerAsJson": vectorLayerAsJson}
});
}, 'displayClass': "olControlSaveFeatures"
});
...
panel.addControls([hand, zoomToDrawControl, drawPointControl, drawPathControl, drawPolygonControl, drawRegularPolygonControl,
new OpenLayers.Control.ZoomToMaxExtent({title:"Zoom to the max extent", text: "World"}), modifyFeatureControl, deleteFeatureControl, save]);
...
map.addControl(panel);
...
Finally when i press the javascript "Save" button, i would like to submit somehow in my backing bean this JSON object ... In particular i would like to call a bean method in order to process JSON object and store it as XML.
Any ideas?