The search pattern
From Wiki
The most common pattern you may want to realize in your Web project is the search pattern. WebRatio provides a simple way to model searches. In this article you see a simple example about how you can model searches and explain which options you have at your disposal.
Suppose to have a data model like the following
The search pattern in this case is applied to the Invoice entity. The invoices search uses different criteria, each one can be used independentòy or in union with other criteria. The search pattern allows to find:
- all the invoices of a specific customer
- all the invoices
- a specific invoice given its number
- all the invoices having the amount in a given range
The search pattern can be modeled in a single page. In this page you need an entry unit to allow the user select which criteria to apply. In this case you need:
- a field to select the customer typing its name or a part of it (string field)
- two fields to select the period of the invoices to find (date fields)
- a field to select the invoice number (integer field)
- two fields to select the amount range of the invoices (float fields)
After modeling the entry unit you have to add the unit showing the search results. You can use either an index unit nor a power index unit to show the invoices list. To this unit you have to add all the selector conditions expressing the criteria listed above. In particular:
- an attribute condition that checks that the customer name begins with the string typed in by the user
- two attribute conditions that check that the invoices are emitted in the date period specified by the user
- an attribute condition that checks that the invoice number is the one entered by the user
- two attribute conditions that check that the total amount is in the range provided by the user
Each condition must be defined as IMPLIED since the user can use only some of the available criteria. Each condition that does not have a value because the user did not consider it must be ignored when retrieving the search results. If you want that a particular condition is mandatory (which means that, if the user do not enter a valid value for it, the search results are not provided), you have to set that condition as REQUIRED. You have also to add to the field related to that condition a validation rule (not null) that advises the user that the field is mandatory.
The last thing you have to decide is if you want to see all the invoices at the start and then filter them using the criteria or if you want to see the results only after the user submits the form. You have to select the Selector node of the index/power index unit in the Outline of the Web project and set the Default Policy. To see all the invoices at start you have to choose the "Fill" value, in the other case the "Empty" value.
At this point the model is completed (see the figure for the web model of the page). You have to set the layout properties for the page and then you can generate and see the result.


