At this stage, you will learn the following features of this version and see them in action:
- Business Components
- New Call Syntax / intellitips in Call
For flights registration, we propose building an alternative way to the one provided by the 'Flights' transaction. It will be built using a Wizard. The transaction business rules will be reused.
The wizard is organized in 5 steps:
1) Entry of flight description and date.
2) Selection of country and city of departure.
3) Selection of country and city of destination.
4) Selection of 'Charter' to be used.
5) Selection of crew and final confirmation.
In the properties of the 'Flights' transaction, setup the 'Business Component' property in 'True'. A Business Component data type will be automatically created, and you will be able to use it in the different KB objects, like any other data type.
Create a 'WZFlights1' Web Panel based on the provided 'WizardStyle' style.
The objective of this case is entering a description and date and save this flight information, and then go to the following step.
So that this wizard will also have the same framework as the other objects, assign the Master Page created in Part 2 to the 'Master Pages' property of the 'WizardStyle' style web panel.
Create a 'Flights' type variable called 'Flight' (business component). Please note that, after you have modified the 'Business Component' property of the 'Flights' transaction so that the corresponding data type was created, two Business Component type data appeared: Flights and Flights.CrewOnBoard (corresponding to the records of the transaction lines).
Insert the 'Flight' variable in the form. Remember that, to insert the Business component (this variable) in the form, you proceed as you do to insert any Structured Data type (SDT) in the form. The following dialog will be displayed, from which you will have to select the members that you want to insert. In this case: 'FliDsc' and 'FliDate'.
The result will be the following:
SDTs and Business components cannot be transferred as parameters in the URL, therefore, we will make them continue in the web server memory (in the websession) using Websession data types and ToXML() and FromXML() methods belonging to the Business Components.
Thus, create a WebSession type variable and program the following:
With this you will save the flight information in the web session, for it to be then retrieved in the wizard next step.
Create a 'WZFlights2' Web Panel based on the 'WizardStyle' style.
The objective is to be able to select country and city, add this data to the flight information and then go to the following step.
Insert a grid in the form to display countries and cities. Setup the 'Allow Selection' grid property in 'True'.
In the events, you must first retrieve the information stored in the previous wizard step and then add this country and city of departure.
Remember defining the Flight variable in every one of these web panels. Try to define it using the contextual menu appearing on right clicking, once the variable name has been typed in the event.
Note 1: The style will also create the Start event to retrieve the 'Flight'. But this is not actually necessary in steps 2 and 5, since no information about it is displayed in the form. You must just retrieve the information in the Next event, as shown in the example above.
Note 2: To make calls between objects, you can use the new call syntax
(In case you transfer parameters in the call, the advantage of using this new syntax is greater, due to the intellitips provided by GeneXus 9.0)
Bear in mind to customize the calls of the Next and Previous events to call the corresponding Wizard instances.
Note 3: You may try adding paging to have a better presentation of the countries/cities.
Create a 'WZFlights3' Web Panel based on the 'WizardStyle' style.
This step is exactly the same as the previous one, except that the country and city to be selected correspond to the flight destination. (The Next event, the country and the city change: the ones corresponding to the flight destination are assigned).
Create a 'WZFlights4' Web Panel based on the 'WizardStyle' style.
This step is also similar to the previous ones, but it provides a Charter to be selected by the user.
Create a 'WZFlights5' Web Panel based on the 'WizardStyle' style.
The objective is to be able to select one or more crew members, add them to the flight information and confirm the flight. If the user succeeds, he will be provided with the flight number and in case he fails, with the causes of the failure.
Unlike in previous steps, now the user must be able to select several lines (several crew members); therefore, a selection variable must be also provided in the grid, in addition to showing the crew data.
Now, the following logic must be programmed:
- Load the flight information already saved (in memory) in previous steps (as you did in the previous steps).
- For each line, in case the line is selected:
- Add the crew member to the flight information
- Save the flight
- If the saving operation is successful, report the flight number assigned
- If the saving operation fails, report the errors occurred.
Please note that:
You must create a Flight.CrewOnBoard type CrewMember variable that 'represents' a line of the 'Flight' transaction.
You must create a Messages.Message type Message variable where you will retrieve each one of the messages resulting from the saving operation. Again, remember that you can define these variables right clicking during codification.
Now, place the 'WzFlights1' Web Panel as main, or add an option to the Web Panel 'Home'; thus, you will be able to execute it more comfortably, without requiring the Developer Menu any more.
Specify, compile and execute these objects to see the result.
With this, you have learn to use Business components, define them and place them in the form, to maintain information in the websession and retrieve them, to save the information of a Business component in the database and to manage the operation errors and successful actions.
Why? -To be more productive in reusing knowledge already existing in the KB, while being mindful of its data integrity constraints and the business rules, fundamental issue in mission critical applications.