List Out All Request Header
//in a controller def showAllHeaders(){ StringBuilder sb = new StringBuilder() request.headerNames.each{ sb.append(it).append(": ").append(request.getHeader(it)) .append("<br>") } render(sb.toString()) }
Showing Message, Error Message, Additional Error Messages in GSP Using Flash
Inside a method in a controller you do:
flash.message = "The request ${camsRequest.getRequestReference()} has been released." //or, and flash.error = "Internal Error. Unable to release this request. If this problem persist, please contact the technical support." //or, and List<String> errorMessages = [] errorMessages.add("First additional error") errorMessages.add("Second additional error") flash.errorMessages = errorMessages
Inside a GSP view, you do:
<div id="message-container" class="container-fluid"> <g:if test="${flash.message}"> <div class="row"> <div class="col-sm-12 alert alert-info"> <b>${flash.message}</b> </div> </div> </g:if> <g:if test="${flash.error}"> <div class="row"> <div class="col-sm-12 alert alert-danger"> <b>${flash.error}</b> <ul> <g:each var="errorMsg" in="${flash.errorMessages}"> <li>${errorMsg}</li> </g:each> </ul> </div> </div> </g:if> <% flash.message = null flash.error = null flash.errorMessages = null %> </div>
Note that we added flash.message = null
, flash.error = null
, and flash.errorMessages = null
to make sure those field are cleaned up. We do this because I something notice that these values in flash
are not being clean after a response.