Results 1 to 2 of 2

Thread: Replacing enums by values contained in a table

  1. #1
    Join Date
    Dec 2011
    Location
    Paris, France
    Posts
    58

    Default Replacing enums by values contained in a table

    Hello,

    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.

    Philroc

  2. #2
    Join Date
    Jun 2008
    Location
    Philadelphia, PA, USA
    Posts
    212

    Default

    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?

    Ken
    Ken Rimple
    Chariot Solutions
    email: krimple@chariotsolutions.com
    work: www.chariotsolutions.com/education
    personal: www.rimple.com

    Author: Spring Roo in Action (Manning)
    MEAP Site: manning.com/rimple

Posting Permissions

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