Connecting a business data source

To be able to display equipment objects, the equipment JSF component must be connected to a data source. This can be done in different ways:
The easiest way to provide server-side customization and business data to an equipment component is through the project tag attribute. It allows you to specify a JViews TGO project that will be set to the underlying IlpEquipment on the server side. For more information, see Loading a project file . Keep in mind that not all CSS view customizations are supported by the equipment JSF component For details, see Equipment view component services .

How to set a JViews TGO project to an equipmentView JSF component

The following example shows how to pass a JViews TGO project to the equipmentView component, and to configure the component dimensions ( width and height ) using the style tag attribute:
<jvtf:equipmentView id="myEquipment" 
                    context="#{contextBean}"
                    style="width:740;height:550" 
                    project="data/myProject.itpr" />
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/example2.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 Rogue Wave JViews TGO is installed.
The id tag attribute defines a unique identifier for the equipmentView component. The context tag attribute is a binding to a bean defined in the faces_config.xml file. The style tag attribute defines two CSS properties ( width and height ) for the dimensions, in pixels, of the equipment component. The project tag attribute is a relative path to a JViews TGO project within the web application. This file should be accessible by the web application.
The following example shows how to declare the context bean in the faces_config.xml file:
<managed-bean>
    <managed-bean-name>contextBean</managed-bean-name>
    <managed-bean-class>
     ilog.tgo.faces.service.IltFacesDefaultContext
    </managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
</managed-bean>
The context should implement the IlpContext interface and must use the synchronization strategy IlSynchronizeOnLockStrategy in order to address the particular threading issues of a web server.

How to declare a dataSource JSF component for the equipment view

Another way to connect business data to the equipment view is through the dataSource JSF component. This component represents a wrapper for an IlpAbstractDataSource object that can be connected to an equipment component. Many different data source components can be declared in a given JSP™ page, but only one can be connected to the equipment view at a time. It is possible to switch data sources dynamically.
The following example shows how to declare a data source in a JSP page:
<jvtf:dataSource id="myDataSource" value="#{dataSourceBean}" />
The id tag attribute defines a unique identifier for the data source component. The value tag attribute gets a value binding to a bean previously declared in the faces_config.xml file that extends IlpAbstractDataSource .

How to connect the dataSource JSF component to the equipmentView JSF component

Once the data source has been declared, you can connect it to the equipment view as follows:
<jvtf:equipmentView id="myEquipment" 
                    context="#{contextBean}"
                    style="width:740;height:550" 
                    dataSourceId="myDataSource" />
The dataSourceId tag attribute gets the unique identifier of the data source component that will connect it to the equipment view.
The following example shows how to declare the dataSource bean in the faces_config.xml file:
<managed-bean>
  <managed-bean-name>dataSourceBean</managed-bean-name>
  <managed-bean-class>ilog.cpl.datasource.IlpDefaultDataSource</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-property>
    <property-name>fileName</property-name>
    <property-class>java.lang.String</property-class>
    <value>data/myEquipment.xml</value>
  </managed-property>
</managed-bean>
The dataSource bean is declared and two properties are set: context and fileName . The context property is set with a value binding to a context bean. It is mandatory, so that the JViews TGO context is consistent across components. The fileName property gets a relative path to an XML file compatible with the data source and accessible from the web application.
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/example3.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 Rogue Wave JViews TGO is installed.

How to set a data source Bean to an equipmentView JSF component

It is also possible to set a data source bean directly to the equipment view component, without requiring the data source component.
For example:
<jvtf:equipmentView id="myEquipment" 
                    context="#{contextBean}"
                    style="width:740;height:550" 
                    dataSource="#{dataSourceBean}" />
The dataSource tag attribute gets a value binding to a bean that extends IlpAbstractDataSource . It will connect the equipment component to this data source bean.

How to use the data tag attribute of the equipmentView JSF component

The equipment view JSF component has a multipurpose data tag attribute, which can be used to connect business data sources using:
  • a JViews TGO XML project file
  • the unique identifier of a data source JSF component
  • the binding to an instance of IlpAbstractDataSource
Note
You must not use any combination of the following tag attributes, which allow you to connect the equipment view to any form of data source:
  • data
  • dataSourceId
  • dataSource
  • project
When used with JViews TGO projects, the data tag attribute behaves exactly like the project attribute, getting the relative path to a JViews TGO project, as in the following example:
<jvtf:equipmentView id="myEquipment" 
                    context="#{myContext}"
                    style="width:740;height:550" 
                    data="data/myProject.itpr" />
Here myProject.itpr is the project file within the web application.
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/example4.jsp.
When used with the unique identifier of a data source JSF component, the data tag attribute behaves exactly like the dataSourceId attribute, getting the unique identifier of a data source component, as in the following example:
<jvtf:equipmentView id="myEquipment" 
                    context="#{myContext}"
                    style="width:740;height:550" 
                    data="myDataSource" />
Here myDataSource uniquely identifies a data source JSF component in the current session.
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/example5.jsp .
When used with an IlpAbstractDataSource instance, the data tag attribute behaves exactly like the dataSource attribute, getting a value binding to a bean that extends IlpAbstractDataSource , as in the following example:
<jvtf:equipmentView id="myEquipment" 
                    context="#{myContext}"
                    style="width:740;height:550" 
                    data="#{dataSourceBean}" />
Here #{dataSourceBean} is a value binding to the corresponding bean declared in the faces_config.xml file.
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/example6.jsp.

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

JSF components allow you to set a backing bean to replace the default component implementation. So, for the equipment view JSF component, the binding attribute can be set with a value binding to a backing bean that extends IltFacesDHTMLEquipmentView (the JavaScript implementation of the equipment view JSF component). The following example illustrates this:
<jvtf:equipmentView id="myEquipment" 
                    context="#{contextBean}"
                    style="width:740;height:550" 
                    binding="#{myJSFEquipment}" />
Here #{myJSFEquipment} is a value binding to a backing bean declared in the faces_config.xml like this:
<managed-bean>
  <description>A bean extending IltFacesDHTMLEquipmentView</description>
  <managed-bean-name>myJSFEquipment</managed-bean-name>
  <managed-bean-class>example.MyEquipmentView</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-equipment-step-by-step/faces/example7.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 Rogue Wave JViews TGO is installed.

How to use the equipment tag attribute of the equipmentView JSF component

It is possible to replace the automatically created IlpEquipment object with a customized equipment object. This is done with the equipment attribute of the equipment view JSF component, as follows:
<jvtf:equipmentView id="myEquipment" 
                    context="#{contextBean}"
                    width="740"
                    height="550"
                    equipment="#{myIlpEquipment.equipment}" />
Here the tag attributes width and height are used to specify the size of the equipment view. Other examples produce the same results using the style tag attribute with the CSS properties " width " and " height ".
In this example, the equipment attribute is set with a method that binds to a bean defined in the faces_config.xml . The corresponding method ( getEquipment in this case) will be invoked when the JSP page is parsed. It allows the user to have access to the IlpEquipment API as well as to its instantiation. Using the equipment attribute and keeping the IlpEquipment in a bean is a good way to provide quick access to the underlying IlpEquipment API within the web application. Note that the context is not passed to the myIlpEquipment.getEquipment 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 'equipment' property
  </description>
  <managed-bean-name>myIlpEquipment</managed-bean-name>
  <managed-bean-class>example.MyEquipment</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-equipment-step-by-step/faces/example8.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 Rogue Wave JViews TGO is installed.