I am currently working on retrieving a variable for a JavaScript function from an object that is sent to the view by the controller.
The object I am dealing with is called Bpmsn.
https://i.sstatic.net/FxlAo.png
Through the controller, I have injected the object into the view.
This is the method in the controller:
@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 is used to display the object.
In the JSP view, I inject the attributes of the object, except for the textXML attribute which will be used 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>
For the textXML attribute, I intend to create a JavaScript function to import that XML into a BPMN modeler. However, I am unsure of how to retrieve the textXML attribute of the injected object in the view from the JavaScript script.
I attempted to call the attribute as done in the view but it was unsuccessful
<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 {
// success!
var canvas = viewer.get('canvas');
canvas.zoom('fit-viewport');
}
});