Created
September 19, 2011 02:07
-
-
Save brunoborges/1225864 to your computer and use it in GitHub Desktop.
Wicket and Scala, the power of DSLs
This file contains 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
val opcoesCha = servico.find() | |
// #1 - regular Scala+Wicket code | |
val chaCozinha = new WebMarkupContainer("chaCozinha") | |
val chaBar = new WebMarkupContainer("chaBar") | |
val chaBarnela = new WebMarkupContainer("chaBarnela") | |
add(chaCozinha, chaBar, chaBarnela) | |
chaCozinha.setDefaultModel(new CompoundPropertyModel(opcoesCha)) | |
chaBar.setDefaultModel(new CompoundPropertyModel(opcoesCha)) | |
chaBarnela.setDefaultModel(new CompoundPropertyModel(opcoesCha)) | |
chaCozinha.add(new Label("dataChaCozinha")) | |
chaCozinha.add(new Label("horaChaCozinha")) | |
chaCozinha.add(new Label("localCozinha")) | |
chaBar.add(new Label("dataChaBar")) | |
chaBar.add(new Label("horaChaBar")) | |
chaBar.add(new Label("localBar")) | |
chaBarnela.add(new Label("dataBarnela")) | |
chaBarnela.add(new Label("horaBarnela")) | |
chaBarnela.add(new Label("localBarnela")) | |
// #2 - DSL'ed Wicket+Scala code | |
val chaCozinha = container("chaCozinha") | |
val chaBar = container("chaBar") | |
val chaBarnela = container("chaBarnela") | |
List(chaCozinha, chaBar, chaBarnela).foreach(c ⇒ c.compound(opcoesCha)) | |
List("data", "hora", "local").foreach(s ⇒ chaBarnela.label(s + "Barnela")) | |
List("dataCha", "horaCha", "local").foreach(s ⇒ chaCozinha.label(s + "Cozinha")) | |
List("dataCha", "horaCha", "local").foreach(s ⇒ chaBar.label(s + "Bar")) | |
// #3 - normalized wicket:ids + DSL'ed Scala + Wicket | |
List("Cozinha", "Bar", "Barnela").foreach(s ⇒ { | |
var c = container(s); c.compound(opcoesCha) | |
List("data", "hora", "local").foreach(l ⇒ c.label(l+s)) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment