Results 1 to 5 of 5

Thread: Enum constants in webflow expression language?

  1. #1
    Join Date
    Oct 2009
    Location
    Czech Republic
    Posts
    29

    Default Enum constants in webflow expression language?

    Hi.

    Is it possible to use enum constant values in the web flow expression language?
    I would like to use something like this:

    Code:
    <evaluate expression="myVariable.myMethod(mypackage.MyClass.MyEnum.HELLO_WORLD)" />
    This does not seem to work for me. Says it cannot be resolved.

    So I am wondering, is this possible? Or what am I doing wrong?

    Thank you!

  2. #2
    Join Date
    Nov 2008
    Posts
    742

    Default

    If you're using OGNL for your expression parser, there's a special way to invoke this.

    The pattern is:

    @package.name.enum.class.name@ENUM_NAME

    So, for your case, you would use:
    @mypackage.MyClass.MyEnum@HELLO_WORLD

    Not sure how to do this with other expression parsers, though.

  3. #3
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    667

    Lightbulb Use T to access a type and $ to access an inner type

    To do this in Spring EL, you would use:

    Code:
    T(mypackage.MyClass$MyEnum).HELLO_WORLD
    Using "$" to access an inner type isn't in the reference docs, I just figured it out using JUnit and some inspired guesswork.
    Andrew Swan
    "Now is the EJB of our discontent made glorious Spring"

  4. #4

    Default

    Thanks for the response, Andrew. I was stuck on this as well and the example you provided solved my problem.

  5. #5
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    667

    Default

    Glad to be of help!
    Andrew Swan
    "Now is the EJB of our discontent made glorious Spring"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •