Monday, October 27, 2008

DSL Widgets in Guvnor

The Drools DSL format has been updated to allow for the addition of metadata to provide for user friendly widgets when using a DSL in combination with the guided editor. The DSL sentence can now display a dropdown for an enumeration, a date selector, a checkbox, and allows for the restriction of the value that can be entered in a text field via a regular expression. The regular expression validates against the contents of the text box and displays a message to the user when an invalid value is entered.Examples of each format are shown below along with screenshots from Guvnor


Defining a dropdown driven by a Guvnor Enum:
Format:
{<variablename>:ENUM:<type.fieldname>}


Example:
[when]When the credit rating is {rating:ENUM:Applicant.creditRating} = applicant:Applicant(credit=="{rating}")





Define a date selector via DSL:
Format:
{<variablename>:DATE:<date>}


Example:
[when]When the applicant dates is after {dos:DATE:dd-MMM-YYYY}=applicant:Applicant(applicationDate>"{dos}")





Defining a checkbox via DSL:
Format:
{<variablename>:BOOLEAN:defaultValue[checked | unchecked]}


Example:
[when]When the applicant approval is {bool:BOOLEAN:checked} =applicant:Applicant(approved=={bool})





Define a restriction on a textbox via a regular Expression:
Format:
{<variablename>:<regex>}


Example:
[when]When the age is less than {num:1?[0-9]?[0-9]} = applicant:Applicant(age<{num})