Customizing the underlying IlpNetwork component

The network view JSF component is a facade to an IlpNetwork component which manages the integration between business data and display data, server-side configuration and interactions. By default, an instance of IlpNetwork is instantiated. However, you can customize the way this underlying component is created, in two different ways:

Using the binding tag attribute

The binding tag attribute allows you to replace the default network view JSF component with a customized backing bean that controls how the IlpNetwork is created through the createNetworkComponent method, as illustrated below:
   protected IlpNetwork createNetworkComponent(IlpContext context,
                                               String config) {
     IlpNetwork myNetwork = new IlpNetwork(config, context);
     IlpDefaultDataSource dataSource = new IlpDefaultDataSource(context);
     try {
       myNetwork.setStyleSheets(new String[] { "myStyles.css" });
       dataSource.parse("myData.xml");
     } catch(Exception x) {
       System.err.println("Could not configure custom component");
     }

     myNetwork.setDataSource(dataSource);

     return myNetwork;
   }

How to use the binding tag attribute of the networkView JSF component

JSF components allow you to set a backing bean to replace the default component implementation. So, for the network view JSF component, the binding attribute can be set with a value binding to a backing bean that extends IltFacesDHTMLNetworkView (the JavaScript implementation of the network view JSF component). The following example illustrates this:
<jvtf:networkView id="aNetwork" 
                    context="#{contextBean}"
                    style="width:740;height:550" 
                    binding="#{myJSFNetwork}" />
Here #{myJSFNetwork} is a value binding to a backing bean declared in the faces_config.xml like this:
<managed-bean>
  <description>A bean extending IltFacesDHTMLNetworkView</description>
  <managed-bean-name>myJSFNetwork</managed-bean-name>
  <managed-bean-class>example.MyNetworkView</managed-bean-class>
  <managed-bean-scope>session</managed-bean-scope>
</managed-bean>
The backing bean provides more flexibility to the user by giving access to the component API and its instantiation.
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-network-step-by-step/faces/example7.jsp .
You will find more information about the sample web application in: <installdir> /samples/faces/jsf-network-step-by-step/index.html where <installdir> stands for the directory where Rogue Wave JViews TGO is installed.

Using the network tag attribute

The network tag attribute allows you to define the customized instance of an IlpNetwork component through method binding. You should declare a bean with a method that returns your instance of IlpNetwork and bind this method with the network tag attribute, as illustrated below:
   public IlpNetwork getCustomNetwork() {
     if (null == network) {
       // Get the default configuration file name
       String config = IltFacesNetworkView.DefaultConfigurationFileName;
       network = new IlpNetwork(config, context);
       IlpDefaultDataSource dataSource = new IlpDefaultDataSource(context);
       try {
         network.setStyleSheets(new String[] { "myStyles.css" });
         dataSource.parse("myData.xml");
       } catch(Exception x) {
         System.err.println("Could not configure custom component");
       }

       network.setDataSource(dataSource);
     }
     return network;
   }
Note
The configuration file is mandatory. The sample uses the default JSF configuration file which is accessible from the property IltFacesNetworkView.DefaultConfigurationFileName .

How to use the network tag attribute of the networkView JSF component

It is possible to replace the automatically created IlpNetwork object with a customized network object. This is done with the network attribute of the network view JSF component, as follows:
<jvtf:networkView id="aNetwork" 
                  context="#{contextBean}"
                  width="740"
                  height="550"
                  network="#{myIlpNetwork.network}" />
Here the tag attributes width and height are used to specify the size of the network view. Other examples produce the same results using the style tag attribute with the CSS properties " width " and " height ".
In this example, the network attribute is set with a method that binds to a bean defined in the faces_config.xml . The corresponding method ( getNetwork in this case) will be invoked when the JSPā„¢ page is parsed. It allows the user to have access to the IlpNetwork API as well as to its instantiation. Using the network attribute and keeping the IlpNetwork in a bean is a good way to provide quick access to the underlying IlpNetwork API within the web application. Note that the context is not passed to the myIlpNetwork.getNetwork method, which means that this bean must be configured with the appropriate context in the faces_config.xml file. For example:
<managed-bean>
  <description>A bean with read access to the 'network' property</description>
  <managed-bean-name>myIlpNetwork</managed-bean-name>
  <managed-bean-class>example.MyNetwork</managed-bean-class>
  <managed-bean-scope>session</managed-bean-scope>
  <managed-property>
    <property-name>context</property-name>
    <property-class>ilog.cpl.service.IlpContext</property-class>
    <value>#{contextBean}</value>
  </managed-property>
</managed-bean>
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-network-step-by-step/faces/example8.jsp .
You will find more information about the sample web application in: <installdir> /samples/faces/jsf-network-step-by-step/index.html where <installdir> stands for the directory where Rogue Wave JViews TGO is installed.