Template:ExampleSearchOfEmployee

From WebRatio WebML Wiki

Jump to: navigation, search

Example {{{1}}}: 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:

  1. 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.
  2. 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".
  3. 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.
  4. 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".
  5. 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.
  6. 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.
  7. 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.
  8. 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=""
    • Required="False"
  9. 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=""
    • Required="False"
  10. 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=""
    • Required="False"
  11. 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.
    Nota 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
  12. 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".
  13. 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.
  14. 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:

  1. 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"
  2. 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"
  3. 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.
  4. 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".
  5. 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.
    Nota 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.
  6. 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.
  7. 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".
  8. 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.
  9. 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