Rule Engine in JavaScript

Pradyumna picture Pradyumna · Oct 5, 2011 · Viewed 12k times · Source

Is there any Rule engine in JavaScript?

The question is in this context:

  • Consider a web application having a form that users fill up.
  • As a user fills up each field and proceeds to the next, business logic written in JavaScript controls the visibility(and other attributes) of form elements further down the page.
  • The same business logic is also applied at the server side after the form gets submitted, albeit, in Java to guard against any mishaps/manipulations at the browser side.

  • Now, Wouldn't it be nice if we have a JSR 94/Drools/JRules like rule engine that would execute rules in both Java and in JavaScript? With such a rule engine, I can avoid hard coding my rules, and I also retain the flexibility of having client-side as well as server-side validation

(PS: I've tried the AJAX route and seen that the application becomes a lot less responsive, making it hard to sell to users who've been accustomed to a hand-coded, pure-javascript version.)

Answer

duffymo picture duffymo · Oct 5, 2011

JSR-94 is a Java specification, so I don't see what it has to do with the browser.

There's Google JSON rules:

http://code.google.com/p/jsonrules/

You said you tried the AJAX route. Does that mean a rules engine running on the server and an asynch call to access it?