I am trying to get a variable for a javascript function from an object that sends it to view by the controller.
The object with which I am working is Bpmsn.
Through the controller I injected the object into view.
My method of the controller is:
@RequestMapping(value = "/display")
public ModelAndView index2(@RequestParam int bpmsnId) {
ModelAndView result;
Bpmsn bpmsn;
bpmsn = bpmsnService.findOne(bpmsnId);
result = new ModelAndView("editor/display");
result.addObject("bpmsn", bpmsn);
return result;
}
This method I use to make a display of the object.
In the jsp view I inject the attributes of the object, except the textXML that I will use in a javascript script.
<div>
<ul>
<li><b><spring:message code="bpmsn.ticker" />:</b> <jstl:out
value="${bpmsn.ticker}" /></li>
<li><b><spring:message code="bpmsn.title" />:</b> <jstl:out
value="${bpmsn.title}" /></li>
<li><b><spring:message code="bpmsn.summary" />:</b> <jstl:out
value="${bpmsn.summary}" /></li>
<li><b><spring:message code="bpmsn.authoredMoment" />:</b> <jstl:out
value="${bpmsn.authoredMoment}" /></li>
<li><b><spring:message code="bpmsn.likes" />:</b> <jstl:out
value="${bpmsn.likes}" /></li>
<li><b><spring:message code="bpmsn.dislikes" />:</b> <jstl:out
value="${bpmsn.dislikes}" /></li>
</ul>
With the textXML attribute I want to create a javascript function to import that xml into a bpmn modeler, but I do not know how to get the textXML attribute of the object injected into the view from the javascript script
I tried to call the attribute as in the view but it does not work
<script type="text/javascript">
var bpmnXML = ${bpmsn.textXML}; //not work
alert(bpmnXML)
// BpmnJS is the BPMN viewer instance
var viewer = new BpmnJS({
container : '#canvas'
});
// import a BPMN 2.0 diagram
viewer.importXML(bpmnXML, function(err) {
if (err) {
// import failed :-(
alert('could not import BPMN 2.0 diagram', err);
} else {
// we did well!
var canvas = viewer.get('canvas');
canvas.zoom('fit-viewport');
}
});
