Switch Unit

From WebRatio WebML Wiki

Jump to: navigation, search



Contents

Introduction

The Switch Unit

The Switch Unit is an Operation Unit used to make an operation chain following different paths depending on the value of its input parameter (just as a SWITCH-CASE construct in programming languages). The unit can follow many different paths, depending on the result of the unit and on the number of cases defined.

Properties

The Properties View of the Switch Unit


  • Id: The unique key automatically assigned by WebRatio to identify the Unit (e.g. switch1e).
  • Name: A meaningful name for the Unit, used as label (e.g. User is guest or is logged).
  • Home: A flag stating that the Switch Unit must be executed as the first operation when the user enters in the related Site View.
  • Case: You can define different CASE values for the unit. A CASE value represents one of the possible values of interest of the Switch Unit input parameter.
  • Default: A flag stating that the Switch Unit must be executed as the first operation when the user enters the Area containing the Unit.
  • Landmark: A flag stating that the link shown in the corresponding Landmark menu that will activate the Unit. If the operation or the operation chain has no outgoing link, the final target page will be the last page visited.
  • Protected: A flag stating that the access to the Switch Unit is granted only to users belonging to groups entitled to access to it.
  • Secure: A flag stating that all the links that can activate the Switch Unit are implemented using the Secure HTTP protocol, instead of the HTTP protocol.
  • Custom Descriptor: A flag stating that the Unit uses a Custom Descriptor.
  • Custom URL Name: The Custom URL Name of the Unit. It is possible to define a custom name that will be used as URL to reach the Switch Unit, instead of the standard Id (used by default). The custom URL name must not contain whitespaces, non-ascii characters or other special characters like /, ?.


Configuration

A Switch 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 Switch Unit
  • Add Link: Adds an outgoing link (of Transport type) to the Unit, which can be used to transport information to other elements.
  • Add OK Link: Adds an outgoing OK Link to the Unit. The OK Link is activated when the Unit performs its operation correctly and can be used to transport information. Moreover, the OK Link will cause the execution of its target element (opens a target page or activates other Operation Units).
  • 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.


Input and Output

The Input and the Output of the Unit are accessible through the Parameters Coupling window of incoming and outgoing Links respectively.

Input

Input configuration of the Switch Unit

The input of the Switch Unit consists of an Input parameter that the Unit will evaluate . To access the input parameter, open the Parameters Coupling dialog with a double click or by selecting the "Coupling" property on an incoming link to the Switch Unit.



Output

Output configuration of the Switch Unit

The Input and the Output of the Unit are accessible through the Parameters Coupling window of incoming and outgoing Links respectively.


Examples

The purpose of this section is to show the usage of the Switch Unit through examples. This example is 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: Logged Employee

Our goal is to give to the user the possibility to see his profile data, in case he has logged in the Web application, or a registration page, in case he is not yet registered. The user will click on the "My Profile" Landmark Selector Unit and the Web application will take him to the correct page. In order to accomplish this example, it is necessary to go through the following steps:

  1. Add a Get Unit to the page: select the Get Unit icon from the palette and place it outside the page. Change the "Name" property in "Get Oid User Logged".
  2. Set the Context Parameter on which the Get Unit is based: click on the "Edit" button next to the "Context Parameter" property in the Properties View. Then choose the "UserCtxParam" Context Parameter from the opened dialog pane.
  3. 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 "My Profile".
  4. 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 "User" Entity from the opened dialog pane.
  5. Add a Key Condition to the Selector Unit. Right Click on the Selector Unit and then on Add Key Condition.
  6. Draw a transport link between the "Get Oid User Logged" Get Unit and the "My Profile" Selector Unit: select the Link button from the palette and click on the "Get Oid User Logged" Get Unit (the Source of the Link) and then on the "My Profile" Selector Unit (the Target of the Link). Set the Name property of the newly created Link to "User data passing" and the Type property to "transport".
  7. Add a Switch Unit: select the Switch Unit icon from the palette and place it inside the Web Model. Change the "Name" property in "User is guest or is logged".
  8. Define the "Case" property: click on the "Edit" button next to the "Case" property, then click on the "Add" button. Insert "0" in the "Define a new value" field and click OK. Click OK on the "Case Editing" dialog.
  9. Draw an OK link between the "My Profile" Selector Unit and the "User is guest or is logged" Switch Unit: select the Link button from the palette and click on the "My Profile" Selector Unit (the Source of the OK Link) and then on the "User is guest or is logged" Switch Unit (the Target of the OK Link). Set the Name property of the newly created OK Link to "Oid data passing".
  10. 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 "Registration Page").
  11. Add a Entry Unit to the page: select the Entry Unit icon from the palette and place it inside the page. Change the "Name" property in "Registration".
  12. Define the Entry Unit fields:right click on the Entry Unit and select the Field Wizard option. In the opened dialog pane, select the User Entity. In the next pane, select the attributes required to complete a registration.
  13. 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 "User Details").
  14. 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 "User Details".
  15. Set the Entity on which the Data Unit is based: click on the "Edit" button next to the "Entity" property in the Properties View. Then choose the "User" Entity from the opened dialog pane.
  16. Draw an OK link between the "User is guest or is logged" Switch Unit and the Registration Page: select the Link button from the palette and click on the "User is guest or is logged" Switch Unit (the Source of the OK Link) and then on the Registration Page (the Target of the OK Link). Set the Name property of the newly created OK Link to "Registration page".
  17. From the Properties view of the link you have created, set the "Case" property to "0"
  18. Draw an OK link between the "User is guest or is logged" Switch Unit and the User details Data Unit: select the Link button from the palette and click on the "User is guest or is logged" Switch Unit (the Source of the OK Link) and then on the User details Data Unit (the Target of the OK Link). Set the Name property of the newly created OK Link to "User Details".
  19. 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 Get Unit
The Properties View of the Selector Unit
The Properties View of the Switch Unit
The "User data passing" Link Parameters Coupling window
The OK Link (pointing to User Details Data Unit) Parameters Coupling window



Related articles:
Category Difficulty Refers
Context Parameters Web Model Beginner Get Unit
Set Unit
Reset Unit
Create Unit Web Model Beginner Create Unit
Create a "Hello world" application Web Model Beginner Site View
WebML
WebRatio
Create a "Simple data centric" web application Web Model Beginner Site View
WebML
WebRatio
Custom Locations and Master pages Web Model Beginner Master Page
Custom Location
… further results












Did you find this article useful? Please rate it!

Rating: 0.0/5 (0 votes cast)

Personal tools