Search code examples
jbossdrools

JBoss Drools - how to get data (facts) from java to DRL


How can I get fact definied by user in GUI and insert it to DRL?

For example: The user has chosen black car in GUI (JavaFX), and now I want to use that fact in DRL code. How to send that info about black car to DRL? Should i use POJO?


Solution

  • If you want to execute rules that you have written in DRL file you have to create a POJO and using KieSession you can execute your rules. For example,

    val pojo = new POJO('POJO arguments') 
    val kieServices = KieServices.Factory.get()
    val kieContainer = kieServices.newKieClasspathContainer()
    val kieSession = kContainer.newKieSession()
    kieSession.insert(pojo)
    kieSession.fireAllRules()
    

    Read this documentation. You can get all the drool-API examples here