Skip to content

Instantly share code, notes, and snippets.

@hatemalimam
Last active May 25, 2017 22:30
Show Gist options
  • Save hatemalimam/344a2f564f1438426bc933eac4fccb58 to your computer and use it in GitHub Desktop.
Save hatemalimam/344a2f564f1438426bc933eac4fccb58 to your computer and use it in GitHub Desktop.
PrimeFaces diagram events
<p:diagram id="diagram" value="#{mainBean.diagramModel}" style="height:400px" styleClass="ui-widget-content" widgetVar="diagramWV" />
<p:growl widgetVar="growlWV" />
<script>
//<![CDATA[
$(document).ready(function () {
setTimeout(function () {
for (var key in PF('diagramWV').canvas.getAllConnections()) {
if (PF('diagramWV').canvas.getAllConnections().hasOwnProperty(key)) {
//Elemenets Events
$(PF('diagramWV').canvas.getAllConnections()[key].source).off('click').on('click', function () {
PF('growlWV').renderMessage({"summary": "Element Clicked with ID",
"detail": $(this).attr('id'),
"severity": "info"});
});
$(PF('diagramWV').canvas.getAllConnections()[key].target).off('click').on('click', function () {
PF('growlWV').renderMessage({"summary": "Element Clicked with ID",
"detail": $(this).attr('id'),
"severity": "info"});
});
//Connection Event
PF('diagramWV').canvas.getAllConnections()[key].bind("click", function (conn) {
PF('growlWV').renderMessage({"summary": "Connection Clicked",
"detail": "Source: " + conn.sourceId + " \n Target: " + conn.targetId,
"severity": "info"});
});
}
}
}, 500);
});
//]]>
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment