Menu

Home

Introduction

DT4J is a Java implementation of decision table execution engine. Decision tables are powerful mode of implementing business rules for your application.

Installation

Download latest zip or tar.gz version. Unpack the content. Add dt4j-xxx.jar and all jar files in the lib folder to your project classpath. It's done.

Usage

Decision Table Creation

Decision tables must be created as an Excel Sheet and it must be present in your project classpath in the default package. Refer DT4J decision table screenshot to learn the format.
dt4j-screenshot

Expression Syntax

DT4J uses powerful expressions module of Spring Framework. Please refer only Expressions chapter as usage of DT4J doesn't require any further knowledge of Spring Framework.

If you have already integrated Spring Framework with your application then you can use even more powerful constructs.

Decision Table Context

Before executing a decision table, you must create decision table context and add variables. Following is the example:

// Sample Domain classes
TaxPayer taxPayer = new TaxPayer(20, Gender.M, 200000);
Tax tax = new Tax();
// Create decision table context
DecisionTableContext context = new DecisionTableContext();
// Add domain class instances as variables so that they are accessible during decision table execution.
context.addVariable("taxPayer", taxPayer);
context.addVariable("tax", tax);

Decision Table Execution

Create an instance of decision table and invoke the execute method. Example:

// ID must match excel sheet name
DecisionTable decisionTable = new DecisionTable("TestDT");
// Pass decision table context as input to execute method
decisionTable.execute(context);

Discussion

  • Swathi M

    Swathi M - 2014-08-01

    DT4J decision table screenshot is not visible if not logged in.

     

    Last edit: Swathi M 2014-08-01
    • technoseals

      technoseals - 2014-08-05

      Thanks for your comment. We have now added the screenshot inline on the wiki page for quicker reference.

       

      Last edit: technoseals 2014-08-05
  • LAIB

    LAIB - 2015-01-27

    Hello, can you give us some docs or more détails with java docs?
    i have an sql database, and i would like to use a table from my database to define rules and actions. Is it possible to do it with dt4j?
    thanks for you answer.

     

    Last edit: LAIB 2015-02-21
    • technoseals

      technoseals - 2015-02-20

      Hi, We are working on creating an admin module that can work with database. But as of now we will recommend you to use only excel sheet based rule authoring.

       
  • LAIB

    LAIB - 2015-02-20

    Hi, thank you for you're answer,
    I tried to use it bat I have a nullPointer error

     
    • technoseals

      technoseals - 2015-02-20

      Hi, your setup looks pretty good. You just need two changes:
      1. TestDT.xls file should be converted into the new excel format TestDT.xlsx
      2. new DecisionTable("TestDT") statement checks for TestDT.xlsx file in the root package. So, either move TestDT.xlsx file to root package or add package path by changing new DecisionTable("TestDT") to new DecisionTable("decisionTable/TestDT").

       
      • LAIB

        LAIB - 2015-02-20

        I have corrected the code and the tax.amount stay always 0!!

         
  • andysol

    andysol - 2015-02-20

    I have everything as mentioned in the example but my tax.setAmount never gets called in the Actions. Posting my code and Rule here for review

    I am not able to debug without the source so may need your help to review the rules and the usage of the library.

    Thanks

     
    • LAIB

      LAIB - 2015-02-20

      same thing for me

       
    • technoseals

      technoseals - 2015-02-20

      Hi, I got the problem in your setup but I feel a sample project is needed. I will ask the team to upload new version of DT4J with a sample project. This should resolve the issues well. Thanks for good feedback so far.

       
      • LAIB

        LAIB - 2015-02-20

        Thank you technoseals

         
        • technoseals

          technoseals - 2015-03-02

          Do try our newer version.

           
  • andysol

    andysol - 2015-02-20

    Could you please point out the setup error and I can try out really quick. Sorry for following up but I have one of my POC's depending on this for completion. :)

    Cant imagine how much this framework makes my design simpler. Thanks for coming up with this simple library.

     

    Last edit: andysol 2015-02-20
    • technoseals

      technoseals - 2015-03-02

      Hi, We have uploaded the new version. It has sample project, javadoc inside dt4j.jar and fix for null pointer issue.

       
  • sree reshmi

    sree reshmi - 2016-02-17

    hi,

    I could not find the location for new version of sample project . Still i am getting 0 as output for all conditions

     
  • fbcyborg

    fbcyborg - 2016-11-13

    Hi,

    I modified the decision table excel file and I get "Illegal Data Type in the cell: 2" but I have no information on what is the wrong cell data type.

     

Log in to post a comment.