Suppose that you have a diagram view showing a number
of nodes and links. You want to display a particular node and center
it on the screen when you click an ICEfaces button. This use case
is shown in the code sample
<install-dir>
/jviews-diagrammer89/codefragments/jsf-diagrammer-ice in
diagrammer.jsp.
Run this sample now to understand the situation better.
The action is initiated on the client side by clicking
a button. However, the task cannot be performed completely on the
client side because there is not enough information on the selected
node. Therefore you have to submit the request to the server and ask
the server to perform more computation.
Once the managed bean on the server side has computed
the offset to be applied to center the selected node on the screen,
you need to find a way to tell the client-side JViews components to apply that offset. For this purpose,
ICEfaces provides a way for you to send JavaScript code from the server
to the client. The code is as follows.
com.icesoft.faces.context.effects.JavascriptContext
.addJavascriptCall(FacesContext.getCurrentInstance(),
"diagrammer.moveTo(300, 500);");
The ICEfaces Ajax agent on the client evaluates the received
JavaScript code in order to scroll the diagram to the expected position.
For more details, see the DiagrammerBean.java file
in the same sample.