Skip to content

Instantly share code, notes, and snippets.

@ripla
Created August 15, 2012 21:08
Show Gist options
  • Save ripla/3363699 to your computer and use it in GitHub Desktop.
Save ripla/3363699 to your computer and use it in GitHub Desktop.
Scaladin registration example 1-1: basic application with a Mongo connection.
import vaadin.scala._
import com.mongodb.casbah.Imports._
import com.novus.salat.grater
import com.novus.salat.global._
import scala.util.Random
import scala.reflect.BeanProperty
class MongoExample extends Application("Mongo & Vaadin, tied together with Scala") {
val registrations: MongoCollection = MongoConnection()("vaadin-scala-mongo-example")("registrations")
def mapRegistrations: List[Registration] = registrations.map(grater[Registration].asObject(_)).toList
def saveRegistration(registration: Registration): Unit = registrations += grater[Registration].asDBObject(registration)
override val main: ComponentContainer = new VerticalLayout
}
case class Registration(
@BeanProperty var username: String = "username" + Random.nextInt,
@BeanProperty var password: String = "",
@BeanProperty var realName: String = "Joe Tester")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment