Search code examples
grailsgspgrails-2.0

How to display different flash.message in different style in GSP page


I have to display different messages using flash.message, some of them have to be in different color, So How to distinguish the flash.message and display them in different color in GSP


Solution

  • the view page code to view error and suces msg in different style

       <g:if test="${flash.message}">
            <div class="message" role="status" style="font-size: medium;color: green;">${flash.message}</div>
        </g:if>
        <g:if test="${flash.warning}">
            <div class="message_error" style="font-size: medium;color: red;">${flash.warning}</div>
        </g:if>
    

    the controller code to call respective label if scues:

    flash.message = message(code: 'Applied Successfully', args: [message(code: 'hrIrRegistration.label', default: 'HrIrRegistration'), hrIrAplcJobAppldLkInstance.id])
                    redirect(controller: "hrIrRegistration", action: "showVcnyForApplcnt", id: params.hrIrVcncyIdHrIrVcncy.id)
    

    if error:

    flash.warning = message(code: 'You have already Applied in this vacancy', args: [message(code: 'hrIrRegistration.label', default: 'HrIrRegistration'), hrIrAplcJobAppldLkInstance.id])
                    redirect(controller: "hrIrRegistration", action: "showVcnyForApplcnt", id: params.hrIrVcncyIdHrIrVcncy.id)