I have thrown together a small Lift application, using CRUDify, to perform basic CRUD operations on some database tables.
Several columns are of type “CHAR (1 byte)“, and are intended to store values of “Y” or “N“. My model class defines those fields like this example:
...
object isActive extends MappedEnum(this, YesNo) {
override def dbColumnName = "IS_ACTIVE"
override def displayName = "Active"
}
...
That type, “YesNo” is a Scala object defined as follows:
object YesNo extends Enumeration {
val Y, N = Value
}
In the web browser forms that are auto-generated by CRUDify, columns such as this do show up with “Y” and “N” as the available options. However, when you create or edit a row… what actually gets stored is “1” or “0“!
Clearly, I’m just missing the boat on something here. How can I structure this such that CRUDify will allow users to select from “Y” or “N” in the browser, and store either “Y” or “N” in the database?
Hmm… not a huge Scala / Lift community here on StackOverflow! Actually, it may be that there isn’t much of a community for this “CRUDify” sub-component of Lift anywhere.
At any rate, I eventually found an answer (sorta) by subscribing to the “liftweb” Google Groups mailing list. Apparently, this is a known limitation in the CRUDify framework. It’s been like that for years and is not a limitation that anyone particularly cares about, but it is known.
One developer back in 2009 tried to find a way around this by creating his own custom subclass of
MappedField, and using that as the mapped type in his Lift model classes. The 140-line class, along with an email briefly describing it, may be found at:http://groups.google.com/group/liftweb/browse_frm/thread/34560f30fab299a7/cdca54c8e1486237?pli=1
I am not sure that this worked 100% back in 2009, and it has a ton of problems when I tried to use it here in 2012 (Scala and Lift have both changed a lot over the past three years).
I invested a small amount of time into trying to make this
MappedFieldsubclass work… and then received approval to choose an approach other than CRUDify. Part of the mission for this little app was to learn some things about what to do and what not to do with Lift, and I think we’ve accomplished that part of the mission now. 🙂However, if this research and sample code helps out someone else down the line later, then that would be great.