skip to main content
Programmer's documentation > Building Web Applications > Developing JViews Maps JSF applications > Contexts for actions on the view
 
Contexts for actions on the view
Describes the contexts in which actions can be executed in response to interactions on the view.
*Overview
* 
*JavaServer Faces lifecycle context
*Explains how to install a select object interactor and a listener in the JSF context.
*Image servlet context
*Describes the value change listener and interactor in the image servlet context.
Overview
Actions executed in response to interactions on the view can be executed in two different contexts: JavaServer™ Faces lifecycle or image servlet. The execution context can be configured by setting the invocationContext attribute on the JSF interactor components.
The value change listeners registered in the interactor can determine whether they are called in a JSF context or in an image servlet context with the following code:
Determining in Which Context a Value Change Listener is Called
 
IlvObjectSelectInteractor source =
        (IlvObjectSelectInteractor)valueChangeEvent.getSource();
boolean jsfContext = source.getInvocationContext() ==
        IlvDHTMLConstants.JSF_CONTEXT;
This section shows the differences between the two invocation contexts through the execution of an action when a node is selected.
JavaServer Faces lifecycle context
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.
Image servlet context
The image servlet uses the same value change listener as the JavaServer™ Faces lifecycle; there is a slight difference in the interactor, which is shown in bold in the example.
Value change listener and interactor in image servlet context (JViews Diagrammer)
 
<jvdf:nodeOrLinkSelectInteractor id="objSelect"
     valueChangeListener="#{diagrammerBean.onSelectNode}"
                 invocationContext="IMAGE_SERVLET_CONTEXT"/>
 
<jvdf:diagrammerView id="diagrammer" interactorId="objSelect" [...] />
Value change listener and interactor in image servlet context (JViews Framework level)
 
<jvf:objectSelectInteractor id="objSelect"
     valueChangeListener="#{frameworkBean.selectObject}"
                 invocationContext="IMAGE_SERVLET_CONTEXT"/>
 
<jvf:view id="view" interactorId="objSelect" [...] />
In this mode the interactor queries an image update. The server fires the value change event just before image generation.
This approach in JViews Diagrammer:
*Avoids submitting the page and refreshes the image only.
*Is outside the JSF lifecycle, so no interaction with JSF components is possible beyond the ability to retrieve the IlvDiagrammer object as shown in Java code of the value-change event.
This method at JViews Framework level:
*Avoids submitting the page and refreshes the image only.
*Is outside the JSF lifecycle, so no interaction with JSF components is possible beyond the ability to retrieve the IlvManagerView as shown in Java code of value-change event

Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.