This article is not up to date and it has been substitute with new up to date content.

Please look the new up to date content.

How to specify complex selector conditions

by Mario Bruno
3,214 views Published on Oct 24, 2011
Applies to: All versions
Table of contents

WebRatio allows you to specify complex conditions using mixed AND/OR logic operators. In order to properly model these conditions you have to use more than one unit to obtain the correct result. Suppose that we want to specify a condition like the following one


  (a < price < b) OR (c < price < d)

where price is the Product price attribute, while a and b are values obtained from other units (for example from an entry unit).

We have to break down the condition into pieces. We have to model three units, the first one extracts objects satisfying the (a < price < b) expression, the second extracts object according to the (c < price < d) expression and the last one extracts objects taking the results of the previous two units and making the OR between them. We can use a selector unit to model the first two pieces of condition, because we don't want to show these units in the Web page.

Let's see how to specify the selector condition (a < price < b) for the first unit. We have to add two attributes condition to the unit, both REQUIRED, connected with the AND logic operator and having price as attribute. The first one will use the Less Than predicate and the second one the Greater Than predicate. The second selector unit has to be modeled in the same way of the first one, expressing the (c < price < d) condition.

Add the entry unit used to pass the values to the selector conditions. Add to it four fields for the a, b, c and d values. Connect the Entry unit to the first selector with a normal link, named Search. Couple the "Less Than" with the b field and the "Greater Than" condition with the a field. Then connect the Entry Unit with the second selector condition using a transport link and couple the couple the "Less Than" with the d field and the "Greater Than" condition with the c field.

At last we model the index unit showing the result. We have to specify two attributes conditions for the unit: the first one takes the results from the first selector unit, the second one the results from the other selector unit. The attributes conditions must be connected with the OR logic operator. The unit must use the EMPTY default policy. Finally, we have to connect the two selector units to the index unit through transport links coupling the first selector output with the first selector condition and the second selector output with the second selector condition.

The figure shows the final model.

The same approach can to be used to model any other complex condition.

How to specify complex selector conditions using selector expressions

It' s possible to combine selector conditions using an arbitrary boolean expression. That means that it is possible to define the expression


 (a < price < b) OR (c < price < d)

just using one unit selector.

The model of the previous section becomes simplier. There are only the Entry Unit with four fields in order to submit the condition values (a, b, c and d) and an Index Unit to show the search results.
Add four attributes conditions to the Index Unit, one for each price condition (a, b, c and d). In the Properties View of the Selector click on the edit button near the Expression property in order to edit the complex condition.



In the opened dialog click on the Explicit the current expression () button in order to edit the expression. The starting expression will appear like in the image below.

Now we have to add the right syntax to the expression. Select "Less than b", "AND", and "Greater than a" elements (CTRL + left click). Surround current selection with brackets clicking on the button. Do the same thing for the "Less than d", "AND", and "Greater than c" elements. Change the boolean operator between the two surrounded expressions from "AND" to "OR".

The result should be:

 

 
 

This article is not up to date and it has been substitute with new up to date content.

Please look the new up to date content.