Hi,

A while ago, I asked if it was possible to use something like MappedEnum
and have some sensible values inserted into the database instead of
integers.

I got the feeling this was not the case, so I've created MappedEnumString
(attached) which maps Enumerations into string values.

Example:
   object TestTypes extends Enumeration {
      val Unknown = new Val(0,"??")
      val Item1 = new Val("XX")
      val Item2 = new Val("YY")
   }

  object test extends MappedEnumString(this, TestTypes, 2)

This will store the values, ??, XX or YY in the db. For display
purposes, it will by default lookup the resource values TestTypes.??,
TestTypes.XX, TestTypes.YY

You can also calculate the displayed values:

    object test2 extends MappedEnumString(this, TestTypes, 2) {
        override def _valueToDisplayString(v:Enumeration#Value) = v match {
            case TestTypes.Item1 => "Item1Display"
            case TestTypes.Item2 => "Item2Display"
            case _ => "Unknown x ItemDisplay"
       }
    }

I'm by no means a Scala/Lift expert so I may have overlooked stuff, so
feel free to comment :-)

/Jeppe


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Attachment: MappedEnumString.scala
Description: MappedEnumString.scala

Reply via email to