Announcement Announcement Module
No announcement yet.
Replacing enums by values contained in a table Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Replacing enums by values contained in a table


    one of my clients would like me to develop a module which will let her update enum values displayed in popup menus in one of my web projects. The problem is that the popup menu values are hard-corded in Java enum classes.

    Is there a relatively-painless way to replace Java enums by values contained in a database table, in a Roo project?

    Will this break Roo's project-update functionality (ie, whenever you modify an enum class in a project, Roo automatically updates the classes that use it)?

    Many thanks.


  • #2
    Easy. Just create an Roo entity with a single value.

    Then, make the switch from the enum to the table relationship (many-to-one) to the new entity.

    Finally, you'll probably have to modify the <field:select> tag to make it set the display to your value column, but that's it.

    You'll be able to scaffold a UI against the code table if you want to.

    Of course, you'll need to load the data from the enum into the table, but then you're done. The only trouble is that you'll have to now check against String values instead of the Enum's static values, but that was your goal, right?