src/main/kotlin/de/uapcore/lightpit/RequestMapping.kt

changeset 210
37fbdcb422b7
parent 209
c9c6abf167c7
child 225
87328572e36f
--- a/src/main/kotlin/de/uapcore/lightpit/RequestMapping.kt	Tue Aug 03 13:41:32 2021 +0200
+++ b/src/main/kotlin/de/uapcore/lightpit/RequestMapping.kt	Tue Aug 03 14:08:08 2021 +0200
@@ -159,11 +159,12 @@
     fun param(name: String): String? = request.getParameter(name)
     fun paramArray(name: String): Array<String> = request.getParameterValues(name) ?: emptyArray()
 
-    fun <T> param(name: String, validator: (String?) -> (ValidationResult<T>), errorMessages: MutableList<String>): T? {
+    fun <T> param(name: String, validator: (String?) -> (ValidationResult<T>),
+                  defaultValue: T, errorMessages: MutableList<String>): T {
         return when (val result = validator(param(name))) {
             is ValidationError -> {
                 errorMessages.add(i18n(result.message))
-                null
+                defaultValue
             }
             is ValidatedValue -> {
                 result.result

mercurial