Java Enum while evaluating conditions in JUEL
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2011 08:01 AM
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
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

Labels:
- Labels:
-
Archive
6 REPLIES 6
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2011 02:40 AM
what if you add the whole package of the enum? eg. org.activiti.enums.JavaEnum ?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2011 12:20 PM
This was obviously my second guess - unfortunately it doesn't work either.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2011 02:36 AM
This will work, although doesn't look as clean as it should
:

${entity.getState().toString().equals("STATE")}
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-01-2011 06:55 AM
This will work, although doesn't look as clean as it should:
${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

It's quite a drawback…
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-01-2011 08:39 AM
We just leverage UEL (JUEL), so it's actually not us not supporting Enums
-> http://download.oracle.com/javaee/5/tutorial/doc/bnahq.html
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

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

${var == 'ORANGE'}
${var == MyEnum.ORANGE}
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-01-2011 09:13 AM
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.
So the proper answer to my first post is:
${entity.getState() == "STATE1"}
or of course
${entity.getState().equals("STATE1")}
It does work in Activiti.
