| Building Web Applications > The Equipment View Faces Component > Configuring an Equipment View Faces Component > Interacting with the Equipment View Component |
Interacting with the Equipment View Component |
INDEX
PREVIOUS
NEXT
|
JViews Framework Faces and core JViews Faces libraries declare predefined interactors that can be connected to the equipmentView component to add extra user interaction. Interactors are faces components that execute client- or server-side actions. Most of them can be extended and configured to suit the user needs.
The following example shows how to declare a predefined interactor (the pan interactor) in the JSP page and connect it to the equipmentView component so that it is always available.
<!-- Declare the predefined 'pan' interactor -->
<jvf:panInteractor id="pan" />
<jvtf:equipmentView id="myEquipment"
context="#{contextBean}"
style="width:740;height:550"
interactorId="pan"
project="data/myProject.itpr" />
In this example, the predefined panInteractor is declared. A unique identifier is associated with it ("pan"). Then, the interactorId tag attribute of the equipmentView component specifies the interactor to be connected to the equipment view.
Usually many interactors are made available in a web application. The following example shows how to declare multiple predefined interactors and how to use image buttons to make them active. Note that only one interactor can be set in the equipment view component at a time. Whenever a new interactor is set, the previous one is removed.
<!-- Declare the predefined 'select' interactor -->
<jvtf:selectInteractor id="select" />
<!-- Declare the predefined 'pan' interactor -->
<jvf:panInteractor id="pan" />
<!-- Create a 4 columns grid -->
<h:panelGrid columns="4">
<!-- Declare a button for selection -->
<jv:imageButton onclick="myEquipment.setInteractor(select)"
buttonGroupId="interactors"
image="images/arrow.gif"
rolloverImage="images/arrowh.gif"
selectedImage="images/arrowd.gif"
title="Select Interactor"
message="Select Interactor" />
<!-- Declare a button for panning -->
<jv:imageButton onclick="myEquipment.setInteractor(pan)"
buttonGroupId="interactors"
selected="true"
image="images/pan.gif"
rolloverImage="images/panh.gif"
selectedImage="images/pand.gif"
title="Pan Interactor"
message="Pan Interactor" />
<!-- Declare a button for zooming in -->
<jv:imageButton onclick="myEquipment.zoomIn(true)"
image="images/zoom.gif"
rolloverImage="images/zoomh.gif"
selectedImage="images/zoomd.gif"
title="Zoom In"
message="Zoom In" />
<!-- Declare a button for zooming out -->
<jv:imageButton onclick="myEquipment.zoomOut(true)"
image="images/unzoom.gif"
rolloverImage="images/unzoomh.gif"
selectedImage="images/unzoomd.gif"
title="Zoom Out"
message="Zoom Out" />
</h:panelGrid>
<jvtf:equipmentView id="myEquipment"
context="#{contextBean}"
style="width:740;height:550"
interactorId="pan"
project="data/myProject.itpr" />
This example defines two predefined interactors:
selectInteractor: This is a server-side interactor that processes object selection by default. (See The selectInteractor Faces Component for details.
panInteractor: This is a client-side interactor that enables panning of the image displayed by the equipment view component.
Two buttons are declared to connect the interactor to the equipment view component. The buttonGroupId tag attribute is used to group image buttons so that only one button of the group is selected at a time. The selected attribute is used to specify which button should be made selected when the page is loaded. This should correspond to the interactor initially connected to the equipment view with the interactorId tag attribute. In this case, the pan button is selected (select="true") and the pan interactor is connected to the equipment view (interactorId="pan").
If you have started the bundled Tomcat web server, the following link will take you to the small sample illustrating this:
http://localhost:8080/jsf-equipment-step-by-step/faces/example13.jsp
You will find more information about the sample web application in:
<installdir>/samples/faces/jsf-equipment-step-by-step/index.html
where <installdir> stands for the directory where ILOG JViews TGO is installed.
The selectInteractor faces component has been defined as an interactor that maps client-side mouse clicks to server-side events dispatched to the underlying view interactor. It extends the JavaServer Faces UICommand component, which means that it will fire ActionEvents to registered ActionListeners.
This component allows you to create customized IlvManagerViewInteractor instances that will process the mouse actions on the client side. By default, it uses the IltSelectInteractor, which allows selecting, dragging and expanding graphic objects.
This interactor has the following limitations in terms of handling events:
BUTTON1 and BUTTON3 mouse buttons are supported (left and middle).
Client-side interactions are converted into the following mouse events, dispatched to the appropriate interactor:
The selectInteractor is declared like any other faces component defined in the JViews TGO faces tag library:
<jvtf:selectInteractor id="select" />
The selectInteractor faces component is configured through the following tag attributes:
Tag Attributes |
Description |
|---|---|
cursor |
Defines the mouse cursor to be used when the interactor is active; it should be one of the cursors supported by the web browser. |
lineWidth |
Defines the width of the interaction area drawn by the interactor. |
lineColor |
Defines the color of the interaction area drawn by the interactor. |
actionName |
Defines the name of the action event triggered by this interactor; it is used to identify events coming from this interactor. |
autoSubmit |
Defines whether the request will be submitted by a mouse click or not; this tag is used to control when the actions are submitted.
When this tag attribute is set to false, the selectInteractor will not submit any request after the user interaction, but wait until some other component does it. |
actionListener |
Defines an action listener that is called when this interactor is used.
Action listeners should implement the ActionListener interface (from JSF library), but JViews TGO faces provide the IltFacesGraphInteractorActionListener abstract implementation that decodes the user interactions into events dispatched to a given view interactor. Subclasses should implement the method getViewInteractor in order to return the appropriate view interactor to process the events. The default implementation (IltFacesSelectInteractorListener) dispatches all events to the IltSelectInteractor view interactor.
Therefore, the actionListener tag attribute may be used to register any ActionListener that will be notified whenever a user interaction has been performed, or a subclass of IltFacesGraphInteractorActionListener can be registered to decode the user interaction into events dispatched to view interactions (IlpViewInteractor). |
invocationContext |
Defines whether the server-side processing is performed in the JSF lifecycle or directly by the image servlet. The possible values are:
The selectInteractor submits requests to be processed on the server side. By default, the request is addressed to the JavaServer Faces controller servlet which processes all requests according to the well-defined JSF lifecycle. This means that all component dependencies will be verified, any registered listener will be notified. The result is a full page refresh with an update of all components involved. If your interaction triggers updates of components other than the equipmentView, then the JSF_CONTEXT should be used.
If, on the other hand, your requests are supposed to only update the image displayed by the equipmentView component, then you may want to benefit from the faster IMAGE_SERVLET_CONTEXT. In this case, the interactor requests will be addressed to the image servlet responsible for generating the image displayed by the equipmentView component. Note that the image servlet has no access to any faces component other than equipmentView, which means that your request cannot rely on other faces components, and that any registered listener for changes on the selectInteractor and equipmentView will not be updated.
There is one exception to this rule. As the overview faces component is largely used with the equipmentView faces component, and as its displayed image is also generated by the image servlet, you can force the overview to be refreshed whenever the main view (equipmentView) is updated, at the cost of an extra client-server-client roundtrip. To do so, you must set the autoRefresh tag attribute of the overview faces component to true. |
binding |
Defines a binding expression to a backing bean. |
The cursor, lineWidth and lineColor tag attributes control the look of the interactor when it is activated, they do not affect its functionality.
If you have started the bundled Tomcat web server, the following links will take you to the small samples illustrating this:
http://localhost:8080/jsf-equipment-step-by-step/faces/example12.jsp
http://localhost:8080/jsf-equipment-step-by-step/faces/example13.jsp
You will find more information about the sample web application in:
<installdir>/samples/faces/jsf-equipment-step-by-step/index.html
where <installdir> stands for the directory where ILOG JViews TGO is installed.
Action listeners are responsible for processing the interactions performed with the select interactor component. Their default behavior is to convert the interactions into server events dispatched to the IltSelectInteractor. It is possible to override this behavior by adding action listeners to the component.
Unlike in the regular equipment Swing component, it is not possible to declare view interactors through a CSS file. Instead, in the equipment faces component, the view interactors are declared within customized action listeners added to the selectInteractor faces component.
As the selectInteractor extends the JavaServer Faces UICommand, it allows one or more action listeners (implementing javax.faces.event.ActionListener) to be registered to receive events (javax.faces.event.ActionEvent) whenever a user interaction is performed. For the ActionEvent API there are the following methods:
getComponent() or getSource(): Return a reference to the interactor faces component that is currently active (for example, IltFacesGraphInteractor).
A predefined abstract implementation of the ActionListener interface named IltFacesGraphInteractorActionListener is provided to translate client-side interactions into server-side events that are dispatched to a given view interactor. When notified, this class translates user interactions into mouse events that are automatically dispatched to the IlpViewInteractor returned by the abstract method getViewInteractor(actionName).
The following example illustrates how to override the default selectInteractor behavior with a customized one:
<jvtf:selectInteractor id="select"
actionListener="#{MyListenerBean}"
invocationContext="JSF_CONTEXT" />
Here the actionListener tag attribute gets a binding to a bean implementing the javax.faces.event.ActionListener interface. Note that actionListener will override the default behavior of the selectInteractor. It is possible to add more than one action listener, combining customized action listeners with the default behavior as shown in the next example:
<jvtf:selectInteractor id="select"
invocationContext="JSF_CONTEXT">
<f:actionListener
type="ilog.tgo.faces.graph.dhtml.event.IltFacesSelectInteractorListener"/>
<f:actionListener type="demo.MyInteractionListener"/>
</jvtf:selectInteractor>
Here IltFacesSelectInteractorListener is the action listener (extends IltFacesGraphInteractorActionListener) that implements the default behavior of the selectInteractor faces component, and MyInteractionListener is a customized implementation of the javax.faces.event.ActionListener interface. The actionListener tag is used to add several action listeners to the selectInteractor, which are invoked in the order in which they have been declared. Note that action listeners may conflict with each other, especially multiple implementations of IltFacesGraphInteractorActionListener, as the first one invoked may change the business model and invalidate the next action listener.
If you have started the bundled Tomcat web server, the following link will take you to the small sample illustrating how to customize action listeners:
http://localhost:8080/jsf-equipment-step-by-step/faces/example14.jsp
You will find more information about the sample web application in:
<installdir>/samples/faces/jsf-equipment-step-by-step/index.html
where <installdir> stands for the directory where ILOG JViews TGO is installed.
The clientSelectInteractor faces component is an interactor designed to minimize the number of image requests and image updates between the graph view on the client and the image servlet on the server by dynamically rendering and managing the selection borders in the client side.
Instead of requesting a new graph view image every time the user selects an object, the clientSelectInteractor dynamically renders an HTML rectangular selection around the object. The server is notified so that the selection model is kept synchronized with the user interactions. A new graph view image is requested only when the user drags objects or interacts with specific decorations (such as information icons, and expansion icons).
The performance and responsiveness is greatly improved as lesser images are generated and dispatched by the server. However, the selection graphic feedback is impacted, as the client is limited to only displaying a rectangular border around the selected object.
The interactor can be configured to work in image mode. In this mode, it will ask the server to process the selection and get a new image on every user interaction. The dynamic selection border will only be displayed while objects are being dragged, as when objects are in their resting position the new image sent by the server already represents the selection.
It is possible to customize the interaction with object decorations, controlling when a click on a particular object decoration should trigger a new image request or not.
The clientSelectInteractor is declared like any other faces component defined in the JViews TGO faces library:
<jvtf:clientSelectInteractor is="clientSelect" />
The clientSelectInteractor faces component is configured through the following tag attributes:
Tag Attributes |
Description |
|---|---|
binding |
Defines a binding expression to a backing bean, allowing the user to customize the clientSelectInteractor faces component. |
message |
Defines the message displayed by the view when the interactor is set. |
cursor |
Defines the mouse cursor to be used when the interactor is active. It should be one of the cursors supported by the web browser. |
menuModeId |
The identifier passed to dynamically generated popup menus. |
moveAllowed |
Specifies whether this interactor allows mouse dragging. |
objectActionMethodBinding |
Defines a method binding to process actions on the object or on specific decorations attached to it. |
onSelectionChanged |
Specifies a JavaScript handler to be called whenever the selection changes. Deprecated in JViews TGO 8.0. See The selectionManager Faces Component for an alternative. |
imageMode |
Sets the interactor to image mode. A new image will be requested every time the user interacts with the view. Deprecated in JViews TGO 8.0. See The selectionManager Faces Component for an alternative. |
lineWidth |
The width of the selection border dynamically rendered by the interactor. Deprecated in JViews TGO 8.0. See The selectionManager Faces Component for an alternative. |
lineColor |
The color of the selection border dynamically rendered by the interactor. Deprecated in JViews TGO 8.0. See The selectionManager Faces Component for an alternative. |
forceUpdateProperties |
Forces the request of additional information when the interactor is in image mode. Used in conjunction with the infoProviderMethodBinding. Deprecated in JViews TGO 8.0. See The selectionManager Faces Component for an alternative. |
infoProviderMethodBinding |
Defines the information provider method binding to return additional information about the selected object. Deprecated in JViews TGO 8.0. See The selectionManager Faces Component for an alternative. |
If you have started the bundled Tomcat web server, the following link will take you to a small sample illustrating this:
http://localhost:8080/jsf-equipment-step-by-step/faces/example19.jsp
You will find more information about the sample web application in:
<installdir>/samples/faces/jsf-equipment-step-by-step/index.html
where <installdir> stands for the directory where ILOG JViews TGO is installed.
By default, the clientSelectInteractor supports interactions with the following object decorations:
If the user clicks on any of these decorations, the interactor triggers a default object action instead of selecting the object. These actions change the look of the objects, which means that a new image is generated.
It is possible to override or even extend this behavior through the objectActionMethodBinding tag attribute, as follows:
<jvtf:clientSelectInteractor id="clientSelect"
objectActionMethodBinding="#{interactorBean.objectAction}" />
Here, the objectActionMethodBinding tag attribute is bound to the objectAction method declared in the interactorBean. The method binding must conform to the following signature:
boolean methodName(IlpGraphView, int, int)
The IlpGraphView is a reference to the graph view containing all the objects. The two integer parameters are the x and y components of the view position where the user has clicked. Returning true indicates that a new image has to be generated, while false indicates that nothing has been processed and the clicked object will be selected.
In the example above, the objectAction method will override the default object action behavior (which is to react on expand, collapse, information and system icons). It is possible to extend this default behavior by overriding the method processObjectAction in class IltFacesDefaultObjectAction.
You can customize the way the selection is performed and displayed by using a selection manager.
This selection manager is defined in a facet on the equipmentView tag, as follows:
<jvtf:equipmentView id="tgoViewId" interactorId="select"> <f:facet name="selectionManager"> <jvtf:selectionManager imageMode="false" [...] /> </f:facet> </jvtf: equipmentView > |
The selection manager has two display modes:
Other parameters can be configured on the selectionManager, like for example the line width or the color of the selection rectangle used in regular selection mode:
<jvtf:selectionManager lineWidth="2" lineColor="red"/>
| Note |
The selection manager currently supports integration with the following TGO Faces interactor: clientSelectInteractor.
|
The selectionManager faces component is configured through the following tag attributes:
You can expose details on the current selection by taking advantage of the property accessor of the selection manager.
The IltFacesPropertyAccessor contains several methods that can be overridden to configure or specialize the way it gives access to model properties. In particular, you can filter the properties that are exposed to clients by overriding the following method:
List getPropertyNames(IlpGraphicView view, IlpRepresentationObject object)
The following code illustrates how to provide your property accessor:
<jvtf:selectionManager propertyAccessor="{#serverBean.propertyAccessor}" [...] />
The following code illustrates how to implement your custom requirements in a new property accessor:
Then you can register a JavaScript listener that will be called when the selection changes:
<jvtf:selectionManager onSelectionChanged="displayProperties(selection)"/>
The JavaScript function can be as follows:
// Alert the ID and bounds of all the selected objects function displayProperties(selection) { for (var i = 0; i < selection.length; i++) alert(selection[i].getID()+"+selection[i].getBounds()); } |
In addition to the ID and bounds properties of the selected object, you can also expose the properties of the selected object in the TGO model as follows:
The following example shows how to use the selection manager with a property accessor:
The selectionManager also allows for changing the selection state of objects programmatically via its client side by means of JavaScript. This can be accomplished by using the following API:
IlvAbstractSelectionManager.selectById(id, extend)
IlvAbstractSelectionManager.selectAll()
IlvAbstractSelectionManager.deselectAll()
Selecting and Deselecting an Object
The selectById function allows you to select or deselect an object by providing the object's identifier:
equipmentView.getSelectionManager().selectById("tgoObjectId");
This method call will select the object with the identifier tgoObjectId and deselect the object currently selected.
You can extend/reduce the current selection by selecting/deselecting a node as follows:
equipmentView.getSelectionManager().selectById("tgoObjectId", true);
This method call keeps the existing selection and selects the object with the identifier tgoObjectId, if it's not already selected; or it will deselect it, if it is already selected.
Selecting All Objects
The selectAll function allows you to select all objects:
equipmentView.getSelectionManager().selectAll();
This method call will select all visible objects.
Deselecting All Objects
The deselectAll function allows you to deselect all objects:
equipmentView.getSelectionManager().deselectAll();
This method call will clear the selection of all visible objects.
| Note |
| In all cases, the object must be selectable in order to get selected. |
The following example shows how to use the selection manager API:
jsf-equipment-step-by-step - Example 22
| Copyright © 1987-2007 ILOG S.A. All rights reserved. Documentation homepage. All rights reserved. Legal terms. | PREVIOUS NEXT |