This topic shows you the JViews JSF code for installing a select
object interactor and a listener. It also shows you the Javaâ„¢ code for writing a value-change
event listener.
In JViews Diagrammer
To select an SDM node in a view, a select object interactor must
be installed on the diagram component view. The
value
property of the interactor holds the IlvSDMNode object that was clicked. Thus, a
valueChangeListener can be
registered to handle the selection event.
Installing a select node or link
interactor and a listener
<jvdf:nodeOrLinkSelectInteractor id="objSelect" valueChangeListener="#{diagrammerBean.onSelectNode}" invocationContext="JSF_CONTEXT"/> <jvdf:diagrammerView id="diagrammer" interactorId="objSelect" [...] />
Note
JSF_CONTEXT
is the default value, so the
invocationContext
attribute could have been omitted.
Java code of the value-change event
The Java code of the value change event
listener is:
public void onSelectNode(ValueChangeEvent event) { IlvSDMNode node = (IlvSDMNode) event.getNewValue(); if (node != null) { //The source of the event is the interactor IlvFacesNodeOrLinkSelectInteractor source = (IlvFacesNodeOrLinkSelectInteractor)valueChangeEvent.getSource(); //Retrieve the JSF view connected to the interactor IlvFacesDiagrammerView jsfDiagrammer = (IlvFacesDiagrammerView)source.getView(); try { //Retrieve the IlvDiagrammer wrapped by the JSF component. IlvDiagrammer diagrammer = jsfDiagrammer.getDiagrammer(); //Select the clicked object diagrammer.deselectAll(); diagrammer.setSelected(node, true); } catch (Exception e) { e.printStackTrace(); } } }
At the JViews Framework level
To select a graphic object in a view at the JViews Framework level, a
select object interactor must be installed on the view. The
value
property of the interactor holds the IlvGraphic object that was clicked. Thus, a
valueChangeListener
can be registered to handle the selection event.
Installing a select object interactor
and a listener
<jvf:objectSelectInteractor id="objSelect" valueChangeListener="#{frameworkBean.selectObject}" invocationContext="JSF_CONTEXT"/> <jvf:view id="view" interactorId="objSelect" [...] />
Note
JSF_CONTEXT
is the default value, so the
invocationContext
attribute could have been omitted.
Java code of value-change event
The Java code of the value change event
listener is:
public void selectObject(ValueChangeEvent event) { Object value = event.getNewValue(); if (value != null && value instanceof IlvGraphic) { //The source of the event is the interactor IlvFacesObjectSelectInteractor source = (IlvFacesObjectSelectInteractor)valueChangeEvent.getSource(); //Retrieve the JSF view connected to the interactor IlvFacesView jsfView = (IlvFacesView)source.getView(); //Retrieve the IlvManagerView wrapped by the JSF component. IlvManagerView managerView = jsfView.getView(); //Select the clicked object IlvGraphic g = (IlvGraphic) value; managerView.getManager().deSelectAll(false); managerView.getManager().setSelected(g, true, false); } }
Note the following concerning the use of
this approach:
- Since the method is called during the JavaServerâ„¢ Faces lifecycle, there can be interaction with other JSF components.
- The form is submitted, so the complete page is reloaded.