Using Enumeration Fields with Lift and CRUDify

I put together a small Lift application using CRUDify to perform basic CRUD operations in some database tables.

Several columns are of type " CHAR (1 byte) " and are designed to store the values ​​of " Y " or " N ". My model class defines fields like this example:

 ... object isActive extends MappedEnum(this, YesNo) { override def dbColumnName = "IS_ACTIVE" override def displayName = "Active" } ... 

This type, " YesNo ", is a Scala object defined as follows:

 object YesNo extends Enumeration { val Y, N = Value } 

In web browser forms that CRUDify automatically generate, columns such as this are displayed as " Y " and " N " as available options. However, when you create or edit a line ... what is actually stored is " 1 " or " 0 "!

Clearly, I just missed the boat for something here. How can I structure this so that CRUDify allows users to select from β€œ Y ” or β€œ N ” in the browser, and store either β€œ Y ” or β€œ N ” in the database?

+4
source share
1 answer

Hmm ... not a huge Scala / Lift community here on StackOverflow! In fact, it’s possible that for this sub-component of β€œCRUDify”, take up a small portion of the community.

Anyway, I eventually found the answer (sorta) by subscribing to the Google Groups Foundry Packages mailing list. This seems to be a well-known limitation in the CRUDify framework. It has been so many years and is not a limitation that someone cares especially, but it is known.

As early as 2009, one developer tried to find a way around this by creating his own subclass of MappedField and using it as a mapped type in his Lift model classes. The 140-line class, along with a message briefly describing it, can be found at:

http://groups.google.com/group/liftweb/browse_frm/thread/34560f30fab299a7/cdca54c8e1486237?pli=1

I'm not sure if this worked 100% in 2009, and it has a lot of problems when I tried to use it here in 2012 (Scala and Lift have changed a lot over the last three years).

I spent a small amount of time trying to make this subclass of MappedField ... and then got approval to choose a different approach than CRUDify. Part of the mission for this small application was to learn something about what to do and what not to do with the Elevator, and I think we completed this part of the mission now. :)

However, if this research and sample code helps someone else down the line later, then it will be great.

0
source

Source: https://habr.com/ru/post/1394458/


All Articles