Skip to content

Instantly share code, notes, and snippets.

@brunoborges
Created July 27, 2011 17:27
Show Gist options
  • Save brunoborges/1109919 to your computer and use it in GitHub Desktop.
Save brunoborges/1109919 to your computer and use it in GitHub Desktop.
Usage of DSLWicket
package code.pages
import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeInstantiation
import org.apache.wicket.markup.html.form.Button
import org.apache.wicket.markup.html.form.Form
import org.apache.wicket.markup.html.WebMarkupContainer
import org.apache.wicket.spring.injection.annot.SpringBean
import org.springframework.stereotype.Service
import code.model.Evento
import code.services.EventosService
import code.DSLWicket
import org.apache.wicket.extensions.yui.calendar.DatePicker
@AuthorizeInstantiation(Array("USER"))
class MeuEvento extends BaseTemplate with DSLWicket {
@SpringBean
var service: EventosService = _
val model = ldm(() ⇒ service.obterEvento(session.usuario.id))
compound(model)
object camposTela extends WebMarkupContainer("campos") with DSLWicket {
label("data")
label("localFesta")
label("enderecoFesta")
label("horaFesta")
label("localCerimonia")
label("enderecoCerimonia")
label("horaCerimonia")
}
add(camposTela)
object formEdit extends Form[Evento]("formEditarInformacoes") with DSLWicket {
compound(ldm(() ⇒ service.obterEvento(session.usuario.id)))
object camposForm extends WebMarkupContainer("campos") with DSLWicket {
dateField("data", "dd/MM/yyyy").add(new DatePicker())
textField("localFesta")
textField("enderecoFesta")
textField("horaFesta")
textField("localCerimonia")
textField("enderecoCerimonia")
textField("horaCerimonia")
setVisibilityAllowed(false)
}
add(camposForm)
object btnSalvar extends Button("btnSalvar") {
setVisibilityAllowed(false)
override def onSubmit() = {
camposForm.setVisibilityAllowed(false)
camposTela.setVisibilityAllowed(true)
btnEditar.setVisibilityAllowed(true)
setVisibilityAllowed(false)
service.salvar(formEdit.getModelObject(), session.usuario.id)
}
}
object btnEditar extends Button("btnEditar") {
override def onSubmit() = {
camposForm.setVisibilityAllowed(true)
camposTela.setVisibilityAllowed(false)
btnSalvar.setVisibilityAllowed(true)
setVisibilityAllowed(false)
}
}
add(btnSalvar)
add(btnEditar)
link("cancelar", () ⇒ {
camposForm.setVisibilityAllowed(false)
camposTela.setVisibilityAllowed(true)
btnEditar.setVisibilityAllowed(true)
btnSalvar.setVisibilityAllowed(false)
})
}
add(formEdit)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment