[rules-users] Problem with Java enums in Guvnor "multiple field constraints"?

Michael Anstis michael.anstis at gmail.com
Wed Oct 5 11:58:04 EDT 2011


This was fixed recently for 5.3.0.Final....

You can use either "multiple field constraints" or "Add more options to this
fields values" (the icon at the end of a field constraint).

On 5 October 2011 16:43, enkidu <paul_blampied at yahoo.co.uk> wrote:

> I've been playing with Drools and Guvnor and think I've encountered a
> problem
> with Java enums in Guvnor. I've searched for previous enum bugs and seen
> that a lot have been fixed, but I've tried Guvnor 5.2.0 and 5.3.0.CR1 and
> it
> happens in both.
>
> The problem seems to happen when you use enums in a "multiple field
> constraint" on a fact, eg:
>
>  There is a Person with:
>    any of the following:
>      role equal to Role.TEACHER
>      role equal to Role.PARENT
>
> Then using "view source" to see the generated DRL, the enum values are
> enclosed in double quotes, ie:
>
>  rule "test"
>      dialect "mvel"
>      when
>          Person( role == "Role.TEACHER" || role == "Role.PARENT" )
>      then
>  end
>
> If I just do a single field constraint then it comes out fine, eg. Person(
> role == Role.TEACHER )
>
> Is this a bug or am I doing something stupid? I've seen posts recommending
> the use of string constants rather than enums - is this the workaround?
>
> Below is my simple Java model for completeness:
>
> public enum Role {
>    TEACHER,
>    STUDENT,
>    PARENT
> }
>
> public class Person {
>
>    private String name;
>    private Role role;
>
>    public Person( String name, Role role ) {
>        this.name = name;
>        this.role = role;
>    }
>
>    public String getName() { return name; }
>
>    public Role getRole() { return role; }
> }
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Problem-with-Java-enums-in-Guvnor-multiple-field-constraints-tp3396901p3396901.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20111005/5c27b1f8/attachment.html 


More information about the rules-users mailing list