Example: Add and remove buttons on Entity Collect screens
This example demonstrates how to hide the Add New Instance and Remove Instance(s) buttons on an Entity Collect screen through the use of custom properties and the modification of velocity templates. Oracle Policy Modeling provides a facility to attach custom property key-value pairs to individual screens and controls during rulebase authoring. These are then exposed to the velocity templates that use them to render the Web Determinations user interface.
Examine the rulebase example
First, we will examine the BonusFlightEligibility rulebase which we will use in this example. This is a simple rulebase that will infer an airline customer's eligibility for a bonus flight based on his/her membership and flights flown details.
- In Oracle Policy Modeling, open the BonusFlightEligibility rulebase project located in <JAVA_RUNTIME_ROOT>\examples\rulebases\source\BonusFlightEligibility.
- Verify the rulebase's boolean Screen custom property; navigate to File -> Project Properties -> Custom Property Definitions -> Screen.

- As seen in the screenshot above, the Hide Remove\Add Instance buttons custom property has a default value of "False". In this example, we will hide the Add New Instance and Remove Instance(s) buttons on the Flights Info entity collect screen. To do this, the value of the custom property Hide Remove\Add Instance buttons for the screen should be "True". This will tell the templates not to display the entity collect buttons on the Flights Info screen. To verify this, open the screens file, right-click on the Flight Info screen and select Custom Properties from the menu.


- That's all the relevant configuration that we need to verify for this rulebase.To test, in Oracle Policy Modeling choose Build and Debug with Screens.
- An interview should open, in which we can determine if "the customer is eligible for a bonus flight". We should be able to verify at this point that we can navigate to all screens. Most input controls cannot be populated since they are read-only.



Modify the Velocity templates
The next task is to modify some Oracle Web Determinations templates to be able to pick-up the screen custom property value and hide the Add New Instance and Remove Instance(s) buttons as necessary. To do this, one must be familiar with the main template and control templates used by Entity-collect Question screens. Information on Oracle Web Determinations templates can be found in Oracle Web Determinations Template Reference Guide.
To illustrate briefly, the entity collect screen is composed of the following templates:

Essentially, what we would like to accomplish is to hide the Remove checkbox; and the Add New Instance and Remove Instance(s) buttons that you can see on the screen in the figure above. To do this, the following changes have to be implemented:
- <OWD deploy dir>\WEB-INF\classes\templates\question_screen.vm
- Set the screen custom property value to a variable.

- <OWD deploy dir>\WEB-INF\classes\templates\controls\ContainmentRelationshipControl.vm
- Add if condition so that the Add New Instance and Remove Instance(s) buttons will not be displayed when hideAddRemoveButtons is "True".

- <OWD deploy dir>\WEB-INF\classes\templates\controls\EntityInstanceCollectGroup.vm
- Add if condition so that the Remove checkbox will not be displayed when hideAddRemoveButtons is "True".

Test the modified templates with the rulebase
In order to test the modifications on the templates, we will create a simple Data Adaptor plugin. For testing purposes, it would simply pre-seed the interview with three "flight info" entity instances. The Java source code of the plugin is can be found in <RUNTIME_ROOT_DIRECTORY>examples\web-determinations\hide-entity-collect-buttons\src.
- Compile the source code above to a JAR file. Call the resulting JAR file, SimpleDataAdaptor.jar.
- Copy the SimpleDataAdaptor.jar file you have created to the plugins directory, where Oracle Web Determinations can find it - <OWD deploy dir>\WEB-INF\classes\plugins.
- Then, deploy your rulebase in Oracle Web Determinations. Copy the rulebase's output file, BonusFlightEligibility.zip, to Oracle Web Determinations' rulebases directory - <OWD deploy dir>\WEB-INF\classes\rulebases.
- Restart your server.
- Open a web browser and navigate to Oracle Web Determinations, passing in any caseID to pre-seed the interview; for example, <server>/<OWD context root>?caseID=777.

- Click on the goal on the Summary screen; you are taken to the Customer Info screen where you can input the following values:
- "What is the customer's name?" - textbox should be pre-seeded with value "John Jones"
- "Is the customer a member of the airline's loyalty program?" - tick "Yes" and click on the Submit button to make the next question visible.
- "What is the customer's airlines loyalty program membership date?" - enter any date that is at least two years older than the current date; for example, 01/24/08.

- Click on the Submit button; you are taken to the Flights Info entity-collect screen where you can verify the following:
- the screen is pre-seeded with three instances.
- the Remove checkbox and the Add New Instance and Remove Instance(s) buttons are hidden.

- Click on the Submit button; the goal is inferred and the interview completed.

- Alternatively, you can set the rulebase's "Hide Remove / Add Instance button" custom property in Oracle Policy Modeling to "False" for the Flights Info entity collect screen.
- Rebuild the rulebase and re-deploy the rulebase output file to the server.
- Re-start the server and start the interview.
- On the Flights Info entity collect screen, verify that the Remove checkbox and the Add New Instance and Remove Instance(s) buttons are all visible.
