Introduction
The Index Unit
The Index Unit is a Content Unit used to display a list of Entity instances. If we draw an outgoing link from this unit, it means that we want to add a link associated to each single row of the list. The outgoing links will contain the information related to the associated row.
Properties
The Properties View of the Index Unit
-
Id: The unique key automatically assigned by WebRatio to identify the Unit (e.g. inu1).
-
Name: A meaningful name for the Unit, used as label (e.g. All employees).
-
Entity: The Data Model Entity on which the Unit is based (e.g. employee).
-
Display Attributes: The list of attributes representing the information shown for each row. The list of available attributes depends on the selected entity (e.g. Name, Surname).
-
Sort Attributes: The sort criteria list applied to the Unit. Each element of this list is composed by an attribute of the selected Entity and it's sort criteria (Ascending or Descending) (e.g. surname, ascending - which means alphabetical order). The position of the elements within the sort criteria list is relevant, since it defines the order in which they are applied.
-
Max Results: A numerical value specifying the maximum number of the retrieved instances above which other instances are ignored by the Unit. If not specified, no row number limit is applied.
-
Distinct: A flag stating that instances having duplicated attribute values have to be removed from the list. The attributes taken into account are those specified in the "Display Attributes" and "Sort Attributes" properties.
-
Link Order: The order of the outgoing links (if any) that will be applied to the links placed on each row of the list.
-
Custom Descriptor: A flag stating that the Unit uses a Custom Descriptor.
Configuration
An Index Unit can be configured through a context menu that can be reached right clicking on the Unit either in the Work Area or in the Outline View. The context menu contains the following options:
The Context Menu of the Index Unit
-
Add Link: Adds an outgoing link to the Unit which can be used to transport information and eventually to activate different actions (such as adding new content to the page, reaching another page with new content, activating operation chains).
-
Add Property: Adds a custom property to the Unit. A Property is composed by Name and Value and permits to mark the element for different purposes.
-
Add Key Condition: Adds a Key Condition to the Unit.
-
Add Attributes Conditions: Adds an Attributes Condition to the Unit.
-
Add Relationship Role Condition: Adds a Relationship Role Condition to the Unit.
Input and Output
The Input and the Output of the Unit are accessible through the Parameters Coupling window of incoming and outgoing Links respectively.
Example of Input Parameters for the Index Unit
Input
The input of the Index Unit consists of all the Conditions defined on the Unit. To access the input parameters, open the Parameters Coupling dialog with a double click or by selecting the "Coupling" property on an incoming link to the Index Unit. Here all the Conditions are listed. Morevore, the Index Unit has a specific Input Parameter:
-
Current Object: The set of key attributes values of the object that defines the current selected object (e.g. Current Oid).
Example of Output Parameters for the Index Unit
Output
The output of the Index Unit consists of all the Attributes of the selected Entity representing the attributes values of the selected row. To access the Output Parameters, open the Parameters Coupling dialog with a double click or by selecting the "Coupling" property on an outgoing link from the Index Unit.
Here all the Output Parameters can be coupled with the Input Parameters of the target elements.
Unit State Object
The Unit State Object for the Index Unit consists of the following properties:
-
int dataSize: the number of entity state objects
-
List data: the list of entity state objects
-
int currentIndex: the zero-based index of the current entity state object
For further reading refer to the Unit State Object article.
Examples
The purpose of this section is to show the usage of the Index Unit through examples. These examples are based on the Data Model shown in the following image.
The Data Model used in the example
|
This Data Model consists of two Entities : "Company" and "Employee". The "Company" entity has many attributes, such as "Name", "E-mail", "Nationality", and so on. The "Employee" entity has attributes such as "Name", "Surname", "Email", "Role" and so on. An Employee belongs to one Company while, obviously, a Company has many Employees. This is represented with the 1:N Relationship "Company_Employee". |
Example 1: The list of companies
Our goal is to show a list of all the companies and allow the user to select a company to see its details. In order to accomplish this example, it is necessary to go through the following steps:
-
Add a Page to the Site View: select the "Page" icon from the palette, and place it on the Site View. Change the page name (setting "Companies") and other properties in the Properties View (such as "Home" or "Landmark" properties) to make the page accessible.
-
Add an Index Unit to the page: select the Index Unit icon from the palette and place it inside the page. Change the "Name" property in "Company List".
-
Set the Entity on which the Index Unit is based: click on the "Edit" button next to the "Entity" property in the Properties View. Then choose the "Company" Entity from the opened dialog pane.
|
|
Since we need to display all the companies contained in the Company Entity, we do not need to define Conditions, so that all instances of the Company Entity will be retrieved. |
-
Choose which attributes of the selected Entity must be shown: click on the "Edit" button of the "Display Attributes" property. Then choose the "Name" and "E-mail" attributes from the opened dialog.
-
Define the sort criteria of the Index Unit: click on the "Edit" button next to the "Sort Attributes" property, then choose the "Name" attribute and the "ascending" sort criteria.
-
Add a Data Unit to the page: select the Data Unit icon from the palette and place it inside the page. Change the "Name" property in "Company Detail".
-
Set the Entity on which the Index Unit is based: click on the "Edit" button next to the "Entity" property in the Properties View. Then choose the "Company" Entity from the opened dialog pane.
-
Choose which attributes of the selected Entity must be shown: click on the "Edit" button of the "Display Attributes" property. Then choose the all attributes from the opened dialog.
-
Draw a normal link between the "Company List" Index Unit and the "Company Detail" Data Unit: select the Link button from the palette and click on the "Company List" Index Unit (the Source of the Link) and then on the "Company Detail" Data Unit (the Target of the Link). Set the Name property of the newly created Link to "View Details" and the Type property to "normal".
-
Define the parameters coupling: open the Parameters Coupling window of the newly created link in order to define the coupling between the output parameters of the source Unit and the input parameters of the target Unit.In the Parameters Coupling dialog, couple the key attribute of the Index Unit with the Key Condition of the Data Unit. This will allow the user to select a company and see its details.
|
|
When the Target and the Source Unit are based on the same entity or on entities connected through a 1:N relationship, WebRatio is able to automatically set the coupling. |
-
Generate the Web application: click on "Generate Full Web Project" on the WebRatio Menu Bar. Once the generation process has completed, it is possible to start the application server and test the Web application.
|
The Web Model of the example
|
The Properties View of the Index Unit
|
The Properties View of the Data Unit
|
The Parameters Coupling window
|
|
The generated Web application
Possible Enhancement
Our goal is to show the list of all the employees related to the company that the user has selected to see its details. In order to accomplish this example, it is necessary to go through the following steps:
-
Add an Index Unit to the page: select the Index Unit icon from the palette and place it inside the page. Change the "Name" property in "Employee List".
-
Set the Entity on which the Index Unit is based: click on the "Edit" button next to the "Entity" property in the Properties View. Then choose the "Employee List" Entity from the opened dialog pane.
-
Choose which attributes of the selected Entity must be shown: click on the "Edit" button of the "Display Attributes" property. Then choose the "Name", "Surname" and "E-mail" attributes from the opened dialog.
-
Define the sort criteria of the Index Unit: click on the "Edit" button next to the "Sort Attributes" property, then choose the "Surname" attribute and the "ascending" sort criteria.
-
Add the Condition for the Company selected: right click on the Index Unit and choose "Add Relationship Role Condition" from the Context Menu. Select the newly added Condition from the Outline View and configure the properties as follow:
-
Name="Employee Company"
-
Role="CompanyToEmployee"
-
Predicate="In"
-
Required="False"
-
Draw a transport link between the "Company Details" Data Unit and the "Employee List" Index Unit: select the Link button from the palette and click on the "Company Details" Data Unit (the Source of the Link) and then on the "Employee List" Index Unit (the Target of the Link). Set the Name property of the newly created Link to "Details" and the Type property to "transport".
-
Define the parameters coupling: open the Parameters Coupling window of the newly created link in order to define the coupling between the output parameters of the source Unit and the input parameters of the target Unit.In the Parameters Coupling dialog, couple the key attribute of the Data Unit with the Relationship Role Condition of the Index Unit. This will allow the user to see the list of employees related to the selected Company.
|
|
When the Target and the Source Unit are based on the same entity or on entities connected through a 1:N relationship, WebRatio is able to automatically set the coupling. |
-
Generate the Web application: click on "Generate Full Web Project" on the WebRatio Menu Bar. Once the generation process has completed, it is possible to start the application server and test the Web application.
|
The Web Model of the enhancement example
|
The Properties View of the Index Unit
|
The Parameters Coupling window
|
|
The generated Web application
Example 2: Search of employees
Our goal is to give the possibility to the user to search among all the employees in the Data Model. The user will be able to search for employees by name, surname and hire date. In order to accomplish this example, it is necessary to go through the following steps:
-
Add a Page to the Site View: select the "Page" icon from the palette, and place it on the Site View. Change the page name (setting "Search Employees") and other properties in the Properties View (such as "Home" or "Landmark" properties) to make the page accessible.
-
Add an Entry Unit to the page: select the Entry Unit icon from the palette and place it inside the page. Change the "Name" property in "Employees Data".
-
Define the Entry Unit fields:right click on the Entry Unit and select the Field Wizard option. In the opened dialog pane, select the Employee Entity. In the next pane, select the "name", "surname" and "hire date" attributes.
-
Add an Index Unit to the page: select the Index Unit icon from the palette and place it inside the page. Change the "Name" property in "Found Employees".
-
Set the Entity on which the Index Unit is based: click on the "Edit" button next to the "Entity" property in the Properties View. Then choose the "Employee" Entity from the opened dialog pane.
-
Choose which attributes of the selected Entity must be shown: click on the "Edit" button of the "Display Attributes" property. Then choose the "name", "surname", "hire date" and "email" attributes from the opened dialog.
-
Define the sort criteria of the Index Unit: click on the "Edit" button next to the "Sort Attributes" property, then choose the "surname" attribute and the "ascending" sort criteria.
-
Add the Condition for the Name-based search: right click on the Index Unit and choose "Add Attributes Condition" from the Context Menu. Select the newly added Condition from the Outline View and configure the properties as follow:
-
Name="Employee name"
-
Attributes="name"
-
Predicate="Begins With (Ignore Case)"
-
Boolean Operator="Or"
-
Value="{{{value}}}"
-
Required="False"
-
Add the Condition for the Surname-based search: right click on the Index Unit and choose "Add Attributes Condition" from the Context Menu. Select the newly added Condition from the Outline View and configure the properties as follow:
-
Name="Employee surname"
-
Attributes="surname"
-
Predicate="Begins With (Ignore Case)"
-
Boolean Operator="Or"
-
Value="{{{value}}}"
-
Required="False"
-
Add the Condition for the Hire Date-based search: right click on the Index Unit and choose "Add Attributes Condition" from the Context Menu. Select the newly added Condition from the Outline View and configure the properties as follow:
-
Name="Employee hire date"
-
Attributes="hire date"
-
Predicate="Less or Equal"
-
Boolean Operator="Or"
-
Value="{{{value}}}"
-
Required="False"
-
Set the Default Policy: expand the Index Unit in the Outline View and select the Selector sub-element. In the Property View set the "Default Policy" property to the "Empty(only with Not Required)" value.
|
|
Setting the Default Policy to "Fill", with all the Conditions with the Required Property set False, means that by default the Unit will show all the employees. The "Empty" values means that at least one search criteria must be provided in order to populate the list |
-
Draw a normal link between the "Employee Data" Entry Unit and the "Found Employees" Index Unit: select the Link button from the palette and click on the "Employee Data" Entry Unit (the Source of the Link) and then on the "Found Employees" Index Unit (the Target of the Link). Set the Name property of the newly created Link to "Search" and the Type property to "normal".
-
Define the parameters coupling: open the Parameters Coupling window of the newly created link in order to define the coupling between the output parameters of the source Unit and the input parameters of the target Unit.In the Parameters Coupling dialog, couple the "name" Field of the Entry Unit with the "Employee name" Attribute Condition of the Index Unit, the "surname" Field of the Entry Unit with the "Employee surname" Attribute Condition of the Index Unit, the "hire date" Field of the Entry Unit with the "Employee hire date" Attribute Condition of the Index Unit.
-
Generate the Web application: click on "Generate Full Web Project" on the WebRatio Menu Bar. Once the generation process has completed, it is possible to start the application server and test the Web application.
|
The Web Model of the example
|
The Properties View of the Entry Unit
|
The Properties View of the Index Unit
|
The Parameters Coupling window
|
|
The generated Web application
Possible Enhancement
Our goal is to give the possibility to the user to search among all the employees in the Data Model even by selecting the Company of which show the related employees. In order to accomplish this example, it is necessary to go through the following steps:
-
Add a Selection Field to the Entry unit: right click on the Entry unit and select "Add Selection Field". Set the "Name" property of the Selection Field to "Company"
-
Add the Condition for the Related Company-based search: right click on the Index Unit and choose "Add Relationship Role Condition" from the Context Menu. Select the newly added Condition from the Outline View and configure the properties as follow:
-
Name="Employee Company"
-
Role="CompanyToEmployee"
-
Predicate="In"
-
Required="False"
-
Change the Parameters Coupling: open the Parameters Coupling window of the link between the Entry Unit and the Index Unit.In the Parameters Coupling dialog, couple the "company" Selection Field of the Entry Unit with the "Employee Company" Relationship role Condition of the Index Unit.
-
Add a Selector Unit to the page: select the Selector Unit icon from the palette and place it inside the page. Change the "Name" property in "All Companies".
-
Set the Entity on which the Selector Unit is based: click on the "Edit" button next to the "Entity" property in the Properties View. Then choose the "Company" Entity from the opened dialog pane.
|
|
Since we need to display all the companies contained in the Company Entity, we do not need to define Conditions, so that all instances of the Company Entity will be retrieved. |
-
Define the sort criteria of the Selector Unit: click on the "Edit" button next to the "Sort Attributes" property, then choose the "name" attribute and the "ascending" sort criteria.
-
Draw a transport link between the "All Companies" Selector Unit and the "Employee Data" Entry Unit: select the Link button from the palette and click on the "All Companies" Selector Unit (the Source of the Link) and then on the "Employee Data" Entry Unit (the Target of the Link). Set the Name property of the newly created Link to "Companies data passing" and the Type property to "transport".
-
Define the parameters coupling: open the Parameters Coupling window of the newly created link in order to define the coupling between the output parameters of the source Unit and the input parameters of the target Unit.In the Parameters Coupling dialog, couple the "oid" Attribute of the Selector Unit with the "company [output]" Selection Field Slot of the Entry Unit and the "name" Attribute of the Selector Unit with the "company [label]" Selection Field Slot of the Entry Unit.
-
Generate the Web application: click on "Generate Full Web Project" on the WebRatio Menu Bar. Once the generation process has completed, it is possible to start the application server and test the Web application.
|
The Web Model of the enhanced example
|
The Parameters Coupling window of the "Search" link
|
The Properties View of the Selector Unit
|
The Parameters Coupling window of the "Companies data passing" link
|
|
The generated Web application