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
<b>Id</b><br/> | |
1<br/> | |
<b>Name</b><br/> | |
My Widget<br/> | |
<b>Price</b><br/> | |
10000<br/> |
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
$.ajax({ | |
beforeSend: function(req) { | |
req.setRequestHeader("Accept", "application/json"); | |
}, | |
type:"GET", | |
url: url, | |
success: function(data){ | |
alert("JSON View=" + data); | |
} | |
}); |
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
{"id":1, "name":"My Widget", "priceInPence":10000} |
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
<html> | |
<head><title>Bowler QuickStart App</title></head> | |
<body> | |
<h2>This is from the default.mustache layout</h2> | |
<div> | |
{{&doLayout}} | |
</div> | |
</body> | |
</html> |
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
// parent layout, that uses a LayoutModel to enrich the layout based on request if needed. | |
val parentLayout = DefaultLayout("default", "doLayout", None, new ParentLayoutModel) | |
// this is a childLayout for parentLayout, and has the parent set on it, as shown. | |
val composableLayout = DefaultLayout("child", "doLayout", Some(parentLayout)) |
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 ParentLayoutModel extends LayoutModel{ | |
def model(request: Request, viewModel: Map[String, Any], childView: String): Map[String, Any] = { | |
val map = new HashMap[String, Any] | |
// lets start by adding the childView so it's guaranteed to appear! | |
map += "doLayout" -> childView | |
// lets see if we want to add a tab panel to this layout! | |
val regex = new Regex("^.*/composable/.*$") | |
if(regex.pattern.matcher(request.getPath).matches){ | |
// using a raw Scalate Template Engine with absolute URI to get and render the template. |
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 MyController extends Controller with ParameterMapper{ | |
post("/widgets/:id")((request, response) => { | |
mapRequest[Widget](request)(widget => { | |
// update the widget | |
Widgets.update(widget) | |
response.sendRedirect("/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
def `GET /widgets/:id`(widget: Option[Widget]) = render(widget) |
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
/** | |
* Transforms from single request parameters to an object, for instance in this case from a Widget ID | |
* to an Actual Widget, or returns None if a transformation cannot be done.<br/> | |
* Must be registered with the TransformerRegistry, as done in the bootstrap above. | |
*/ | |
class WidgetTransformer extends StringValueTransformer[Widget]{ | |
def toValue(from: String): Option[Widget] = Widgets.find(Integer.parseInt(from)) | |
} |
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
// Register the WidgetTransformer so that we can look up Widgets for pages by ID | |
TransformerRegistry.registerTransformer(classOf[Widget], classOf[WidgetTransformer]) |