My favorites
▼
|
Sign in
scala-spring
Scala spring
Project Home
Downloads
Wiki
Issues
Source
Checkout
Browse
Changes
Source path:
svn
/
trunk
/
samples
/
petclinic
/
src-scala
/
org
/
springframework
/
samples
/
petclinic
/
web
/
AddOwnerForm.scala
r20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package org.springframework.samples.petclinic.web
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Controller
import org.springframework.ui.Model
import org.springframework.validation.BindingResult
import org.springframework.web.bind.annotation.ModelAttribute
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.SessionAttributes
import org.springframework.web.bind.annotation.InitBinder
import org.springframework.web.bind.support.SessionStatus
import org.springframework.web.bind.WebDataBinder
import org.springframework.samples.petclinic.Clinic
import org.springframework.samples.petclinic.Owner
import org.springframework.samples.petclinic.validation.OwnerValidator
@Controller
@RequestMapping(Array("/addOwner.do"))
@SessionAttributes {val types = Array(classOf[Owner])}
class AddOwnerForm {
private var clinic:Clinic = null
@Autowired
def setClinic(clinic:Clinic) = this.clinic = clinic
@InitBinder
def setAllowedFields(dataBinder:WebDataBinder) = {
dataBinder.setDisallowedFields(Array("id"))
}
@RequestMapping {val method = Array(RequestMethod.GET)}
def setupForm(model:Model):String = {
val owner = new Owner()
model.addAttribute(owner)
return "ownerForm"
}
@RequestMapping {val method = Array(RequestMethod.POST)}
def processSubmit(@ModelAttribute owner:Owner, result:BindingResult, status:SessionStatus):String = {
new OwnerValidator().validate(owner, result)
if (result.hasErrors()) {
return "ownerForm"
} else {
this.clinic.storeOwner(owner)
status.setComplete()
return "redirect:owner.do?ownerId=" + owner.id
}
}
}
Show details
Hide details
Change log
r13
by rintcius on May 29, 2009
Diff
Ported web and validation classes to scala
Go to:
...ork/samples/petclinic/validation
.../validation/OwnerValidator.scala
...ic/validation/PetValidator.scala
.../validation/VisitValidator.scala
...etclinic/validation/package.html
...gframework/samples/petclinic/web
...petclinic/web/AddOwnerForm.scala
...s/petclinic/web/AddPetForm.scala
...petclinic/web/AddVisitForm.scala
...b/ClinicBindingInitializer.scala
...linic/web/ClinicController.scala
...etclinic/web/EditOwnerForm.scala
.../petclinic/web/EditPetForm.scala
...tclinic/web/FindOwnersForm.scala
...etclinic/web/PetTypeEditor.scala
...mples/petclinic/web/package.html
...ork/samples/petclinic/validation
...gframework/samples/petclinic/web
Project members,
sign in
to write a code review
Older revisions
All revisions of this file
File info
Size: 1794 bytes, 52 lines
View raw file
Powered by
Google Project Hosting