This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.bowlerframework.controller.Controller | |
import org.bowlerframework.model.{ ParameterMapper, Validations} | |
import org.bowlerframework.view.{Renderable} | |
/** | |
* | |
* extends: | |
* - Controller: used to construct routes and deal with them by providing functions that respond to routes. | |
* - ParameterMapper: takes a request and maps any values into beans or other objects. | |
* - Validations: validation enables the Controller |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.recursivity.commons.validator._ | |
import org.bowlerframework.model.DefaultModelValidator | |
/** | |
* Validates a widget - requires a .properties file on the classpath with the same package and class as this class. | |
*/ | |
class WidgetValidator(widget: Widget) extends DefaultModelValidator(classOf[WidgetValidator]) { | |
// adding individual field validators. The string key is the key used to lookup the property name for the error message. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Checks uniqueness of a Widget for create | |
*/ | |
class UniqueValidator(func: => Long) extends Validator { | |
def getKey = "id" | |
def getReplaceModel = List[Tuple2[String, Any]]() | |
def isValid: Boolean = { | |
if (Widgets.find(func) == None) return true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NotNullOrNoneValidator={key} cannot be null or empty | |
StringLengthValidator={key} must be between {min} and {max} characters long | |
MaxIntValidator={key} can be at most {max} | |
MinIntValidator={key} must be at least {min} | |
MinLongValidator={key} must be at least {min} | |
UniqueValidator={key} must be unique | |
id=ID | |
name=Name | |
yearMade=Year Made |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h3>Create new Widget</h3> | |
<ul> | |
{{#validationErrors}} | |
<li>{{.}}</li> | |
{{/validationErrors}} | |
</ul> | |
{{#widget}} | |
<form method="POST" action="/widgets"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// form for creating a new Widget - passes in a new, empty widget to be filled out. | |
get ("/widgets/new")((request, response) => {render(Widget(0, null, 0))}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.bowlerframework.view | |
import org.bowlerframework.{Request, Response} | |
/** | |
* Strategy for resolving a ViewRenderer given a request | |
*/ | |
trait RenderStrategy{ | |
def resolveViewRenderer(request: Request): ViewRenderer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% import org.bowlerframework.view.scalate.SimpleComponent._ %> | |
<%@ val tuple: scala.Tuple2[String, String] %> | |
Here is your template body.. | |
${unescape(show(tuple))} | |
..here's the rest of your template body |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.squeryl.Schema | |
// setup Squeryl Schema with a single entity type/table | |
object Library extends Schema { | |
val authors = table[Author]("authors") | |
} | |
// setup CRUD Controller - gives you full CRUD serverside behavior with JSON rendering etc! | |
val dao = new LongKeyedDao[Author](authors) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SquerylController extends InterceptingController { | |
def around(request: Request, response: Response)(controller: (Request, Response) => Unit) = { | |
val session = SessionFactory.newSession | |
session.bindToCurrentThread | |
try{ | |
transaction{ | |
controller(request, response) | |
} | |
}finally{ | |
session.close |