skip to main content
Programmer's documentation > Building Web Applications > Developing JViews Charts 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.
*Introduction
*Describes the JavaServer Faces lifecycle and image servlet contexts for actions on the view.
*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.
Introduction
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 Charts
To highlight a point in a chart view, a chart select interactor must be installed on the chart view. The value property of the interactor holds the IlvDataSetPoint that was clicked. Thus, a valueChangeListener can be registered to handle the selection event.
Installing a chart select interactor and a listener
 
<jvcf:chartSelectInteractor id="selectInteractor"
                  valueChangeListener="#{demoBean.pointSelected}"
 
                  pickingMode="item"
                              invocationContext="JSF_CONTEXT">
<jvcf:chartView id="chart" 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 pointSelected(ValueChangeEvent evt) {
  IlvDataSetPoint point = (IlvDataSetPoint) evt.getNewValue();
 
  if (point != null) {
 
              //The source of the event is the interactor
    IlvObjectSelectInteractor interactor =
                  (IlvObjectSelectInteractor) evt.getSource();
              //Retrieve the JSF view connected to the interactor
     IlvChartDHTMLView jsfView = (IlvChartDHTMLView) interactor.getView();
 
              //Retrieve the IlvChart wrapped by the JSF component.
    IlvChart chart = jsfView.getChart();
    //Set a pseudo class on the display point.
    //A CSS rule like point:selected { ... }
                    //will customize the graphic representation of the point.
    chart.setPseudoClasses(point.getDataSet(),
                           point.getIndex(),
                           new String[]{"selected"} );
 
}
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 Charts)
 
<jvcf:chartSelectInteractor id="selectInteractor"
                  valueChangeListener="#{demoBean.pointSelected}"
 
invocationContext="IMAGE_SERVLET_CONTEXT">
                  pickingMode="item"
<jvcf:chartView id="chart" 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 Charts:
*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 IlvChart object as shown in Java code of the value-change event

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