cancel
Showing results for 
Search instead for 
Did you mean: 

Java Enum while evaluating conditions in JUEL

mlisiewicz
Champ in-the-making
Champ in-the-making
Is it possible to use java enum while evaluating conditions in JUEL?
e.g.
I want to  choose route from exclusive gateway based on state of process entity, where state is java enum. Comparison fails cause enum class is not visible in JUEL expression.

${entity.getState() == JavaEnum.STATE1}

I hope I made it clear  Smiley Wink
6 REPLIES 6

jbarrez
Star Contributor
Star Contributor
what if you add the whole package of the enum? eg. org.activiti.enums.JavaEnum ?

mlisiewicz
Champ in-the-making
Champ in-the-making
This was obviously my second guess - unfortunately it doesn't work either.

frederikherema1
Star Contributor
Star Contributor
This will work, although doesn't look as clean as it should Smiley Wink:

${entity.getState().toString().equals("STATE")}

mlisiewicz
Champ in-the-making
Champ in-the-making
This will work, although doesn't look as clean as it should Smiley Wink:

${entity.getState().toString().equals("STATE")}

Well,
in this case I read Your answer as: We just figured out that we do not support Java Enums Smiley Wink
It's quite a drawback…

frederikherema1
Star Contributor
Star Contributor
We just leverage UEL (JUEL), so it's actually not us not supporting Enums Smiley Wink -> http://download.oracle.com/javaee/5/tutorial/doc/bnahq.html
When referencing an enum constant with an expression, you use a String literal. For example, consider this Enum class:

public enum Suit {hearts, spades, diamonds, clubs}
To refer to the Suit constant, Suit.hearts with an expression, you use the String literal, "hearts". Depending on the context, the String literal is converted to the enum constant automatically. For example, in the following expression in which mySuit is an instance of Suit, "hearts" is first converted to a Suit.hearts before it is compared to the instance.

${mySuit == "hearts"}

So the workaround is not a workaround, actually it's the way to do this… Don't really see what the drawback is. All there is to it, is their name, so typing in a literal string in an expression is exactly the same as using enum Smiley Wink

${var == 'ORANGE'}
${var == MyEnum.ORANGE}

mlisiewicz
Champ in-the-making
Champ in-the-making
Actually You are right, it works like that :shock:
So the proper answer to my first post is:

${entity.getState() == "STATE1"}
or of course
${entity.getState().equals("STATE1")}

It does work in Activiti.