i need to access the data object of an org.primefaces.model.diagram.Element in a managedBean on click of this very element. I am using primefaces 5.2. I tried multiple ways to establish this, but none did work so far. Here is one approach:
xhtml:
the idea is, to pass the element through a commandLink action attribute (which works fine for e.g. data tables):
<fl:composition template="/WEB-INF/template.xhtml" xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:fl="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui">
<fl:define name="content">
<h:form id="form">
<p:diagram style="height:600px" value="#{flowDiagramBean.model}" var="el">
<f:facet name="element">
<p:commandLink actionListener="#{flowDiagramBean.onElementClicked}" update="@form" value="#{el.actionElementLabelText}">
<f:attribute name="element" value="#{el}"/>
</p:commandLink>
</f:facet>
</p:diagram>
</h:form>
</fl:define>
</fl:composition>
The inital build up of the prototypes diagram:
@PostConstruct
public void init() {
setModel(new DefaultDiagramModel());
getModel().setMaxConnections(-1);
getModel().getDefaultConnectionOverlays().add(new ArrowOverlay(20, 20, 1, 1));
FlowChartConnector connector = new FlowChartConnector();
connector.setPaintStyle("{strokeStyle:'#C7B097',lineWidth:3}");
getModel().setDefaultConnector(connector);
ScreenFlowItemObj screenFlowItemObj = new ScreenFlowItemObj();
screenFlowItemObj.setActionElementLabelText("test");
Element start = new Element(screenFlowItemObj, "20em", "6em");
start.addEndPoint(new BlankEndPoint(EndPointAnchor.BOTTOM));
start.addEndPoint(new BlankEndPoint(EndPointAnchor.LEFT));
Element trouble = new Element(screenFlowItemObj, "20em", "18em");
trouble.addEndPoint(new BlankEndPoint(EndPointAnchor.TOP));
trouble.addEndPoint(new BlankEndPoint(EndPointAnchor.BOTTOM));
trouble.addEndPoint(new BlankEndPoint(EndPointAnchor.RIGHT));
model.addElement(start);
model.addElement(trouble);
}
As you can see, the type ScreenFlowItemObj is the passed data object of each element.
The actionListener looks like this:
public void onElementClicked(ActionEvent event) {
ScreenFlowItemObj screenFlowItemObj = (ScreenFlowItemObj) event.getComponent().getAttributes().get("element");
}
Unfortunately on click of the commandLink the attribute "element" does not get put to the attribute map, so in the listener screenFlowItemObj resolves to null. Am i doing something wrong? Might there be another way to make this happen?
I am using primefaces 5.2 on a 1.7 tomee with JSF 2.2.
Thank you,
Gunnar