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

changeset 210
37fbdcb422b7
parent 209
c9c6abf167c7
child 225
87328572e36f
equal deleted inserted replaced
209:c9c6abf167c7 210:37fbdcb422b7
157 private fun jspPath(name: String) = Constants.JSP_PATH_PREFIX.plus(name).withExt(".jsp") 157 private fun jspPath(name: String) = Constants.JSP_PATH_PREFIX.plus(name).withExt(".jsp")
158 158
159 fun param(name: String): String? = request.getParameter(name) 159 fun param(name: String): String? = request.getParameter(name)
160 fun paramArray(name: String): Array<String> = request.getParameterValues(name) ?: emptyArray() 160 fun paramArray(name: String): Array<String> = request.getParameterValues(name) ?: emptyArray()
161 161
162 fun <T> param(name: String, validator: (String?) -> (ValidationResult<T>), errorMessages: MutableList<String>): T? { 162 fun <T> param(name: String, validator: (String?) -> (ValidationResult<T>),
163 defaultValue: T, errorMessages: MutableList<String>): T {
163 return when (val result = validator(param(name))) { 164 return when (val result = validator(param(name))) {
164 is ValidationError -> { 165 is ValidationError -> {
165 errorMessages.add(i18n(result.message)) 166 errorMessages.add(i18n(result.message))
166 null 167 defaultValue
167 } 168 }
168 is ValidatedValue -> { 169 is ValidatedValue -> {
169 result.result 170 result.result
170 } 171 }
171 } 172 }

mercurial