Introduction to the Oracle Business Rules Editor Component

25-6 Oracle Fusion Middleware Developers Guide for Oracle SOA Suite Figure 25–12 Validation Panel to Manage Error Messages

25.2.2 How to Create and Run a Sample Application by Using the Rules Editor Component

This section lists the steps for creating and running a sample application by using the Rules Editor component. The prerequisite for using the Rules Editor component to create ADF-based Web applications is having a running installation of Oracle SOA Suite and Oracle JDeveloper on your computer. To create a sample application by using the Rules Editor: The first task is to create a sample application. The steps are: 1. Open Oracle JDeveloper.

2. From the File menu, select New and then Generic Application to create an

application.

3. Enter a name for the application in the Application Name field, for example,

useRulesDCApp, and click Next as shown in Figure 25–13 . Figure 25–13 Creating a Generic Application

4. Enter useRulesDC in the Project Name field and ensure that ADF Faces is

selected in the Project Technologies tab as shown in Figure 25–14 . Note: Once all the edits are done, the component user is responsible for saving the ruleset. Using Declarative Components and Task Flows 25-7 Click Finish to create the project. Figure 25–14 Creating a Project

5. Right-click the useRulesDC project in the Application Navigator of Oracle

JDeveloper, and select Project Properties to display the Project Properties dialog box. In the Project Properties dialog box:

a. Click JSP Tag Libraries from the left panel.

b. Click Add and select ADF Faces Components from the Extension list in the

Choose Tag Libraries dialog box, and click OK as shown in Figure 25–15 . Figure 25–15 Choosing Tab Libraries 25-8 Oracle Fusion Middleware Developers Guide for Oracle SOA Suite

c. Click Libraries and Classpath from the left panel and click the Add Library

button to display the Add Library dialog box.

d. Click Oracle Rules and Oracle Rules Editor Component from the Extension

list and then click OK as shown in Figure 25–16 . Figure 25–16 Selecting Oracle Rules and Rules Editor Component This adds the Rules SDK and the Rules Editor Component tag libraries to the project.

e. Click OK to close the Project Properties dialog box.

6. Select Save All from the Oracle JDeveloper File menu to save the project.

You have to ensure that all the required tag libraries are added:

1. Right-click the useRulesDC project in the Application Navigator of Oracle

JDeveloper and select Project Properties to display the Project Properties dialog box.

2. Click JSP Tag Libraries from the left panel and check if all the tag libraries are

added as shown in Figure 25–17 . Using Declarative Components and Task Flows 25-9 Figure 25–17 Checking the Required Tag Libraries To create the RuleSetModel object: The Rules Editor component requires a oracle.bpel.rulesdc.model.impl.RuleSetModel object. The component uses this object to read the rules and the decision tables that exist in the ruleset. So, the next task is to create a managed bean called SomeBean.java that creates a RuleSetModel object. The steps are:

1. Open Oracle JDeveloper.

2. From the File menu, select New to display the New Gallery dialog box.

3. In the New Gallery dialog box, select Java under General from the Categories

panel. Ensure that Java Class under Items is selected and click OK to display the Create Java Class dialog box.

4. Enter the name of the Java class, for example SomeBean.java, and click OK to

create the Java class in your project as shown in Figure 25–18 . 25-10 Oracle Fusion Middleware Developers Guide for Oracle SOA Suite Figure 25–18 Creating a Java Class 5. In SomeBean.java, provide a method that returns the RuleSetModel object. You must specify the location of the rules file here. The following is a sample of the SomeBean.java file: package userulesdc; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.Reader; import java.io.Writer; import java.util.ArrayList; import java.util.List; import oracle.bpel.rulesdc.model.impl.RuleSetModel; import oracle.rules.sdk2.dictionary.RuleDictionary; import oracle.rules.sdk2.exception.SDKException; import oracle.rules.sdk2.exception.SDKWarning; import oracle.rules.sdk2.ruleset.RuleSet; import oracle.rules.sdk2.ruleset.RuleSetTable; public class SomeBean { private static final String RULES_FILE = your rules file here; private RuleSetModel ruleSetModel = null; public RuleSetModel getRuleSetModel { if ruleSetModel = null return ruleSetModel; cache ruleSetModel instead of re-creating it each time Reader reader = null; try { reader = new FileReadernew FileRULES_FILE; } catch FileNotFoundException e {