Multiple Values Assignment
Given a M-N relationship between two entities, sometimes it's necessary to assign a set of values of one of the entites to one of the second one in a user-friendly form.
Assign many Roles to a User.
Given the M-N relationship:
One of the most common implementation of this pattern is to have a form that receive the first entity as parameter (in this case User), and shows two listboxes, the first one with the list of not assigned values of the second entity (Roles) and the second one with the already assigned values. Usually there are two buttons to move values from one listbox to the other.
If the set of possible values (Roles in this case) is small, the listboxes can be replaced with a grid with checkboxes (because each value can be assigned or not).
Implementation of Multiple Values Assignment Pattern
For the generation of the default instance file, it is important to have User transaction defined as two-levels transaction:
Multiple Values Assignment Pattern Instance File
The Instance File has the following nodes:
- BaseTransaction - In this case User Transaction.
- AssignmentTransaction - It is the Transaction that the values will be taken to assign, in this case Role Transaction. Multiple Values Pattern will take primary keys of these two Transactions to generate for eachs, news and deletes of the corresponding data.
- AssignmentWebPanel - Web Panel with two list boxes that allows the assignment between Roles to a User.
In this Web Panel you can configure the following properties:
- Object Name
- If the Web Panel will be Web Component
- Master Page
- HelperObjects - In this node you can specify the names of the procedures to assign and to delete values between User and Roles.
Fantastic Theme and BasicDomain (Boolean domain) are consolidated in the KB the first time the pattern is applied.
In this file you can configure:
- Name of the folder for GeneXus objects
- Name of the generated objects
- Default Master page
Generated GeneXus Objects
By default this pattern generates the following objects:
- AssignRoleToUser Web Panel - This Web Panel receives a user as parameter and allows to assign or delete Roles to the given User.
The Web Panel has two list boxes, one of them with the Assigned Roles and the other with availables Roles.
- AddRoleToUser y DelRoleToUser Procedures - This procedures are called from the Web Panel to add or remove User's Roles.
You must copy the files in MultipleValues.zip
under C:\Program Files\ARTech\Patterns11\Patterns directory.
Next time you execute Pattern this pattern will be available in patterns list.