Reputation: 16841
From my grails Controller class i need to show an error message from the GSP file.
def myControllerMethod() {
if (fruit==apple){
// Do something
} else {
Show the error message, from the GSP file.
}
}
In the GSP file. I have the following code which is the error message i want to show for 5 seconds and then it should disappear.
<body>
...
<div class="alert alert-danger" role="alert">
<a href="#" class="alert-link">...</a>
</div>
</body>
Upvotes: 0
Views: 412
Reputation: 1036
You need Javascript / JQuery for that. Below an example:
setTimeout( function(){
$('div.alert').fadeOut("slow"); },
5000 );
More information with setTimeout here
You can also use delay() (more information here)
Example:
def myController() {
def message
if (fruit==apple){
// Do something
} else {
message = 'Your message'
}
return [message:message, ...]
}
In your view:
<g:if test="${ message }">
...
</g:if>
And don't forget to enable alert:
$(".alert").alert()
Hope this helps
Upvotes: 1