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})




5 comments:

  1. Could it be that you keep on forgetting

    semicolons after

    &gt

    and after

    &lt

    ??

    ReplyDelete
  2. Ah yeah. It renders correctly in IE but not Firefox. I'll fix it now

    ReplyDelete
  3. I've tried using this same method to perform tests against Java enum types, to no avail. Suggestions/examples on how to do this?

    ReplyDelete
  4. camerono: For now the enumerated type has to be defined in Guvnor via the Enumerations Asset. I agree that it would make sense to extend it to imported models with Enums, but it isn't their right now.

    ReplyDelete
  5. The boolean check box is incorrect, you need quotes around the end part like this: [when]This Security is Ratable {bool:BOOLEAN:checked}=ratable:Ratable(ratableValue=="{bool}")

    ReplyDelete